AtCoder Grand Contest 010

Submission #1357210

Source codeソースコード

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
using namespace std;

#define fi first
#define se second
typedef long long LL;
typedef long double LD;

int N,a[100010];

int gcd(int a, int b){
    if (!b) return a;
    return gcd(b,a%b);
}

bool get_ans(){
    int cnte=0,i,gc=0;
    bool g=1; LL sum=0;
    for (i=1; i<=N; i++){
        if (a[i]%2==0) cnte++;
        sum+=a[i];
        if (a[i]==1) g=0;
    }

    if (!g) return (sum-N)%2;

    if (cnte%2) return 1;
    else if (N-cnte>1) return 0;
    else {
        for (i=1; i<=N; i++){
            if (a[i]%2) a[i]--;
            gc=gcd(a[i],gc);
        }
        for (i=1; i<=N; i++)
            a[i]/=gc;

        return !get_ans();
    }
}
int main(){
    cin >> N;

    int i;
    for (i=1; i<=N; i++)
        cin >> a[i];

    bool ans=get_ans();
    if (ans) cout << "First\n";
    else cout << "Second\n";

    return 0;
}

Submission

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

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 54 ms 640 KB
in10.txt AC 53 ms 640 KB
in11.txt AC 59 ms 640 KB
in12.txt AC 53 ms 640 KB
in13.txt AC 58 ms 640 KB
in14.txt AC 68 ms 640 KB
in15.txt AC 57 ms 640 KB
in16.txt AC 67 ms 640 KB
in17.txt AC 56 ms 640 KB
in18.txt AC 71 ms 640 KB
in19.txt AC 54 ms 640 KB
in2.txt AC 54 ms 640 KB
in20.txt AC 64 ms 640 KB
in21.txt AC 61 ms 640 KB
in22.txt AC 60 ms 640 KB
in23.txt AC 61 ms 640 KB
in24.txt AC 60 ms 640 KB
in25.txt AC 56 ms 640 KB
in26.txt AC 60 ms 640 KB
in27.txt AC 57 ms 640 KB
in28.txt AC 61 ms 640 KB
in29.txt AC 56 ms 640 KB
in3.txt AC 53 ms 640 KB
in30.txt AC 60 ms 640 KB
in31.txt AC 53 ms 640 KB
in32.txt AC 54 ms 640 KB
in33.txt AC 57 ms 640 KB
in34.txt AC 62 ms 640 KB
in35.txt AC 59 ms 640 KB
in36.txt AC 1 ms 256 KB
in37.txt AC 1 ms 256 KB
in4.txt AC 54 ms 640 KB
in5.txt AC 53 ms 640 KB
in6.txt AC 54 ms 640 KB
in7.txt AC 53 ms 640 KB
in8.txt AC 54 ms 640 KB
in9.txt AC 53 ms 640 KB
sample1.txt AC 1 ms 256 KB
sample2.txt AC 1 ms 256 KB
sample3.txt AC 1 ms 256 KB