Cod sursa(job #2715428)

Utilizator MateiAruxandeiMateiStefan MateiAruxandei Data 3 martie 2021 17:46:05
Problema Bowling Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.28 kb
#include <bits/stdc++.h>

#define NMAX 50005
using namespace std;

ifstream fin("bowling.in");
ofstream fout("bowling.out");

int dp[NMAX], nr[NMAX], ok[205], sg[305];

int main()
{
    for(int nrP = 3; nrP <= 100; ++nrP)
    {
        memset(ok, 0, sizeof(ok));
        for(int j = 0; j < nrP; ++j)
            ok[sg[nrP] ^ sg[nrP - j - 1]] = 1;
        for(int j = 0; j < nrP - 1; ++j)
            ok[sg[nrP] ^ sg[nrP - j - 2]] = 1;
        for(int j = 0; j <= 200; ++j)
            if(!ok[j])
            {
                sg[nrP] = j;
                break;
            }
    }
    int t;
    fin >> t;

    while(t--)
    {
        int n;
        fin >> n;

        int lg = 0, rez = 0, ax = -1;
        for(int i = 1; i <= n; ++i)
        {
            int x;
            fin >> x;

            if(x == 1)
                ++lg;
            else
            {
                if(lg <= 71)
                    ax = sg[lg];
                else ax = sg[72 + (lg - 72) % 12];
                rez ^= ax;
            }
        }
        if(lg <= 71)
            ax = sg[lg];
        else ax = sg[72 + (lg - 72) % 12];
        rez ^= ax;

        if(rez == 0)
            fout << "Fumeanu\n";
        else fout << "Nargy\n";
    }
    return 0;
}