Cod sursa(job #2412320)

Utilizator Alex_BubBuburuzan Alexandru Alex_Bub Data 22 aprilie 2019 00:26:15
Problema Bowling Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <fstream>
#include <vector>
#include <cstring>

using namespace std;

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

const int NMax = 85;

int Mex[NMax + 5], N, L, Ans, T; bool A[2 * NMax + 5];

vector <int> V;

int FindMex(int K)
{
    for(int i = 0; i < K; i++)
        V.push_back(Mex[i] ^ Mex[K - i - 1]);

    for(int i = 0; i < K - 1; i++)
        V.push_back(Mex[i] ^ Mex[K - i - 2]);

    memset(A, 0, sizeof(A));

    while(V.size()) A[V.back()] = 1, V.pop_back();

    for(int i = 0; i <= 2 * NMax + 3; i++)
        if(A[i] == 0)
            return i;
}

int Get(int x)
{
    if(x >= 73) x = 73 + (x - 73) % 12;

    return Mex[x];
}

int main()
{
    fin >> T;

    for(int i = 1; i < NMax; i++)
        Mex[i] = FindMex(i);

    while(T--)
    {
        fin >> N; L = Ans = 0;

        for(int i = 1, x; i <= N; i++)
            fin >> x, ((x == 1) ? (L++) : (Ans ^= Get(L), L = 0));

        Ans ^= Get(L); fout << ((Ans) ? "Nargy" : "Fumeanu") << '\n';
    }
    fin.close();
    fout.close();

    return 0;
}