304 North Cardinal St.
Dorchester Center, MA 02124

# Zeta-Nim Game CodeChef Solution

## Zeta-Nim Game CodeChef Solution in C++14

``````#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(12);

const int MAXN = 2012;
vector<vector<int>> SG(MAXN +1, vector<int>(MAXN + 1, 0));
const int N = MAXN + 100;
vector<char> ok(N + 1, false);

vector<int> que(MAXN + 10);
for (int i = 1; i <= MAXN; ++i) {
int mex = 0;
int sz = 0;
for (int j = 1; j <= MAXN; ++j) {
if (j <= i) {
int x = SG[i - j][j];
if (!ok[x]) {
ok[x] = true;
que[sz++] = x;
}
}
while (ok[mex]) {
++mex;
}
SG[i][j] = mex;
}
for (int j = 0; j < sz; ++j) {
ok[que[j]] = false;
}
}

int t;
cin >> t;
while (t-- > 0) {
int n;
cin >> n;
int K;
cin >> K;
vector<int> A(n);
for (int i = 0; i < n; ++i) {
cin >> A[i];
}

int ans = 0;
K = min(K, MAXN);
for (auto x : A) {
ans ^= SG[x][K];
}
if (ans != 0) {
cout << "Nancy\n";
} else {
cout << "Zeta\n";
}
}

return 0;
}``````

## Zeta-Nim Game CodeChef Solution in C

``````#include<stdio.h>
int G[2015][2015];
int main(){
int t,k,n,A[55],i,j,B[2015],a,xor=0;

for(i=0;i<=2012;i++)G[0][i]=0;
for(i=1;i<=2012;i++){
a=0;
for(j=0;j<=i;j++)B[j]=0;
for(j=1;j<=i;j++){
B[G[i-j][j]]=1;
while(B[a]==1)a++;
G[i][j]=a;
}
for(;j<=2012;j++)G[i][j]=G[i][i];
}

scanf("%d",&t);
while(t--){
xor=0;
scanf("%d %d",&n,&k);
if(k>=2012)k=2012;
for(i=0;i<n;i++)scanf("%d",&A[i]);
for(i=0;i<n;i++){xor^=G[A[i]][k];}
if(xor)printf("Nancy\n");
else printf("Zeta\n");

}

return(0);

}
``````

## Zeta-Nim Game CodeChef Solution in JAVA

``````import java.io.BufferedReader;
import java.io.IOException;

public class Main{
public static void main(String[] args) throws IOException {
String input[];
int N, K;
int i, j, k;
int A[];
int G[][] = new int[2013][2013];
int points[] = new int[2013];
long ans = 0;
int mex;

for (i = 1; i < 2013; i++) {
for (j = 0; j <= i; j++) {
points[j] = 0;
}
mex = 0;
k = 0;
for (j = 1; j < 2013; j++) {
if (j <= i) {
points[G[i - j][j]] = 1;
}
while (k <= 2013) {
if (points[k] == 0) {
mex = k;
break;
}
k++;
}
G[i][j] = mex;
}
}

for (k = 0; k < T; k++) {
N = Integer.parseInt(input[0]);
K = Integer.parseInt(input[1]);
A = new int[N];

for (i = 0; i < N; i++) {
A[i] = Integer.parseInt(input[i]);
}

ans = 0;
for (i = 0; i < N; i++) {
ans ^= G[A[i]][Math.min(A[i], K)];
}

if (ans == 0) {
System.out.println("Zeta");
} else {
System.out.println("Nancy");
}
}
}
}``````

## Zeta-Nim Game CodeChef Solution in GO

``````package main

import (
"bufio"
"fmt"
"os"
)

func readInt(bytes []byte, from int, val *int) int {
i := from
sign := 1
if bytes[i] == '-' {
sign = -1
i++
}
tmp := 0
for i < len(bytes) && bytes[i] != ' ' {
tmp = tmp*10 + int(bytes[i]-'0')
i++
}
*val = tmp * sign
return i
}

func readNum(scanner *bufio.Scanner) (a int) {
scanner.Scan()
return
}

func readTwoNums(scanner *bufio.Scanner) (a int, b int) {
a, b = res[0], res[1]
return
}

func readNNums(scanner *bufio.Scanner, n int) []int {
res := make([]int, n)
filleNNums(scanner, n, res)
return res
}

func filleNNums(scanner *bufio.Scanner, n int, res []int) {
x := 0
scanner.Scan()
for i := 0; i < n; i++ {
for x < len(scanner.Bytes()) && scanner.Bytes()[x] == ' ' {
x++
}
}
}

func main() {
scanner := bufio.NewScanner(os.Stdin)

for tc > 0 {
tc--
filleNNums(scanner, n, nums)
res := solve(n, k, nums)
if res {
fmt.Println("Nancy")
} else {
fmt.Println("Zeta")
}
}
}

const MAX = 2013

var grundy [MAX * MAX]int
var nums []int

func init() {
var used [MAX]bool
for stones := 1; stones < MAX; stones++ {
for i := 0; i < MAX; i++ {
used[i] = false
}
var next int
for k := 1; k < MAX; k++ {
if stones >= k {
used[grundy[(stones-k)*MAX+k]] = true
for next < MAX && used[next] {
next++
}
}
grundy[stones*MAX+k] = next
}
}
nums = make([]int, 60)
}

func solve(n int, k int, stones []int) bool {
var res int
for i := 0; i < n; i++ {
x := min(stones[i], k)
res ^= grundy[stones[i]*MAX+x]
}
return res != 0
}

func min(a, b int) int {
if a <= b {
return a
}
return b
}``````
##### Zeta-Nim Game CodeChef Solution Review:

In our experience, we suggest you solve this Zeta-Nim Game CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Zeta-Nim Game CodeChef Solution.

Find on CodeChef

##### Conclusion:

I hope this Zeta-Nim Game CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.

Keep Learning!