Cod sursa(job #2715440)

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

#define NMAX 50005
using namespace std;

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

int ok[205], sg[305];

int main()
{
    sg[1] = 1, sg[2] = 2;
    for(int nrP = 3; nrP <= 100; ++nrP)
    {
        memset(ok, 0, sizeof(ok));
        for(int j = 0; j < nrP; ++j)
            ok[sg[j] ^ sg[nrP - j - 1]] = 1;
        for(int j = 0; j < nrP - 1; ++j)
            ok[sg[j] ^ 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 <= 72)
                    ax = sg[lg];
                else ax = sg[72 + (lg - 72) % 12];
                rez ^= ax;
                lg = 0;
            }
        }
        if(lg <= 72)
            ax = sg[lg];
        else ax = sg[72 + (lg - 72) % 12];
        rez ^= ax;

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