Cod sursa(job #3234586)

Utilizator DobraVictorDobra Victor Ioan DobraVictor Data 10 iunie 2024 10:48:18
Problema Bowling Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.37 kb
#include <iostream>
#include <fstream>
#include <stdint.h>
#include <bitset>

const int32_t LOOP_START = 73;
const int32_t LOOP_LEN = 12;
const int32_t CASE_COUNT = LOOP_START + LOOP_LEN;
const int32_t MAX_VAL = 1000;

int32_t vals[CASE_COUNT];
int main() {
	std::ifstream fin("bowling.in");
	std::ofstream fout("bowling.out");

	vals[0] = 0;
	vals[1] = 1;
	vals[2] = 2;

	for(int32_t i = 3; i != CASE_COUNT; ++i) {
		std::bitset<MAX_VAL> bset;

		for(int32_t j = 0; j != i; ++j)
			bset[vals[j] ^ vals[i - j - 1]] = 1;
		for(int32_t j = 1; j != i; ++j)
			bset[vals[j - 1] ^ vals[i - j - 1]] = 1;

		for(; bset[vals[i]]; ++vals[i]);
	}

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

		int32_t len = 0, sum = 0;
		for(int32_t i = 0; i != n; ++i) {
			int32_t val;
			fin >> val;

			if(val) {
				++len;
			} else {
				int32_t usedLen;
				if(len >= CASE_COUNT) {
					usedLen = LOOP_START + (len - LOOP_START) % LOOP_LEN;
				} else {
					usedLen = len;
				}
				sum ^= vals[usedLen];
				len = 0;
			}
		}
		if(len) {
			int32_t usedLen;
			if(len >= CASE_COUNT) {
				usedLen = LOOP_START + (len - LOOP_START) % LOOP_LEN;
			} else {
				usedLen = len;
			}
			sum ^= vals[usedLen];
		}

		if(sum) {
			fout << "Nargy\n";
		} else {
			fout << "Fumeanu\n";
		}
	}

	fin.close();
	fout.close();

	return 0;
}