AtCoder Grand Contest 010

Submission #1588174

Source codeソースコード

#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int n,a[100010];
int gcd(int x,int y)
{
	if (!y)
	{
		return x;
	}
	else
	{
		return gcd(y,x%y);
	}
}
bool nim()
{
	long long s=0;
	bool f=false;
	int cnt=0;
	for (int i=1;i<=n;i++)
	{
		s+=a[i]-1;
		if (a[i]==1)
		{
			f=true;
		}
		if (a[i]&1)
		{
			cnt++;
		}
	}
	if (f)
	{
		return s%2;
	}
	if ((n-cnt)%2)
	{
		return true;
	}
	if (cnt==1)
	{
		for (int i=1;i<=n;i++)
		{
			if (a[i]&1)
			{
				a[i]--;
				break;
			}
		}
		int g=a[1];
		for (int i=2;i<=n;i++)
		{
			g=gcd(g,a[i]);
		}
		for (int i=1;i<=n;i++)
		{
			a[i]/=g;
		}
		return !(nim());
	}
	return false;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	if (nim())
	{
		puts("First");
	}
	else
	{
		puts("Second");
	}
    return 0;
}

Submission

Task問題 D - Decrementing
User nameユーザ名 Emma194
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 1000
Source lengthソースコード長 1857 Byte
File nameファイル名
Exec time実行時間 43 ms
Memory usageメモリ使用量 640 KB

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:119:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
./Main.cpp:122:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a[i]);
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample1.txt,sample2.txt,sample3.txt
All 1000 / 1000 sample1.txt,sample2.txt,sample3.txt,in1.txt,in10.txt,in11.txt,in12.txt,in13.txt,in14.txt,in15.txt,in16.txt,in17.txt,in18.txt,in19.txt,in2.txt,in20.txt,in21.txt,in22.txt,in23.txt,in24.txt,in25.txt,in26.txt,in27.txt,in28.txt,in29.txt,in3.txt,in30.txt,in31.txt,in32.txt,in33.txt,in34.txt,in35.txt,in36.txt,in37.txt,in4.txt,in5.txt,in6.txt,in7.txt,in8.txt,in9.txt,sample1.txt,sample2.txt,sample3.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
in1.txt AC 12 ms 640 KB
in10.txt AC 13 ms 640 KB
in11.txt AC 22 ms 640 KB
in12.txt AC 13 ms 640 KB
in13.txt AC 20 ms 640 KB
in14.txt AC 38 ms 640 KB
in15.txt AC 18 ms 640 KB
in16.txt AC 36 ms 640 KB
in17.txt AC 17 ms 640 KB
in18.txt AC 43 ms 640 KB
in19.txt AC 21 ms 640 KB
in2.txt AC 13 ms 640 KB
in20.txt AC 38 ms 640 KB
in21.txt AC 23 ms 640 KB
in22.txt AC 22 ms 640 KB
in23.txt AC 21 ms 640 KB
in24.txt AC 24 ms 640 KB
in25.txt AC 21 ms 640 KB
in26.txt AC 22 ms 640 KB
in27.txt AC 22 ms 640 KB
in28.txt AC 24 ms 640 KB
in29.txt AC 21 ms 640 KB
in3.txt AC 12 ms 640 KB
in30.txt AC 21 ms 640 KB
in31.txt AC 12 ms 640 KB
in32.txt AC 12 ms 640 KB
in33.txt AC 23 ms 640 KB
in34.txt AC 26 ms 640 KB
in35.txt AC 23 ms 640 KB
in36.txt AC 1 ms 256 KB
in37.txt AC 1 ms 256 KB
in4.txt AC 12 ms 640 KB
in5.txt AC 13 ms 640 KB
in6.txt AC 13 ms 640 KB
in7.txt AC 13 ms 640 KB
in8.txt AC 12 ms 640 KB
in9.txt AC 12 ms 640 KB
sample1.txt AC 1 ms 256 KB
sample2.txt AC 1 ms 256 KB
sample3.txt AC 1 ms 256 KB