Cod sursa(job #2445144)

Utilizator stefdascalescuStefan Dascalescu stefdascalescu Data 2 august 2019 18:08:34
Problema Bowling Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1 kb
#include<bits/stdc++.h>
using namespace std;
ifstream f("bowling.in");
ofstream g("bowling.out");
int t;
int n;
int sg[50002];
int pz[50002];
void calc()
{
    sg[1] = 1;
    pz[0] = 1;
    for(int i = 2; i <= 100; ++i)
    {
        for(int j = 0, k = i-1; j <= k; ++j, --k)
            pz[sg[j] ^ sg[k]] = i;
        int pp = 0;
        while(pz[pp] >= i-1)
            ++pp;
        sg[i] = pp;
    }
    for(int i = 101; i <= 50000; ++i)
        sg[i] = sg[i-12];
}
int main()
{
    calc();
    f >> t;
    for(; t; --t)
    {
        f >> n;
        int st = 0;
        int xorsum = 0;
        for(int i = 1; i <= n; ++i)
        {
            int pp;
            f >> pp;
            if(pp == 0)
            {
                xorsum ^= sg[st];
                st = 0;
            }
            else
                ++st;
        }
        xorsum ^= sg[st];
        if(xorsum)
            g << "Nargy\n";
        else
            g << "Fumeanu\n";
    }
    return 0;
}