We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution
{
static void Main(string[] args)
{
// Read the input
string[] input = Console.ReadLine().Split(' ');
int n = int.Parse(input[0]);
int m = int.Parse(input[1]);
int[] firstRow = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
// Call the method to compute the last row
int[] lastRow = XorMatrix(n, m, firstRow);
// Print the result
Console.WriteLine(string.Join(" ", lastRow));
}
static int[] XorMatrix(int n, int m, int[] firstRow)
{
int[] previousRow = firstRow;
int[] currentRow = new int[n];
// Generate each row from the second to the last row
for (int i = 1; i < m; i++)
{
for (int j = 0; j < n; j++)
{
currentRow[j] = previousRow[j] ^ previousRow[(j + 1) % n];
}
// Update the previous row to the current row for the next iteration
previousRow = (int[])currentRow.Clone();
}
// The last generated row is stored in previousRow
return previousRow;
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
XOR Matrix
You are viewing a single comment's thread. Return to all comments →
the problem is resolution
using System; using System.Collections.Generic; using System.IO; using System.Linq;
class Solution { static void Main(string[] args) { // Read the input string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]);
}