結果

問題 No.761 平均値ゲーム
ユーザー pppppp
提出日時 2018-12-09 19:10:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 6,308 bytes
コンパイル時間 1,116 ms
コンパイル使用メモリ 110,328 KB
実行使用メモリ 11,892 KB
最終ジャッジ日時 2023-10-14 14:28:30
合計ジャッジ時間 5,905 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,428 KB
testcase_01 AC 1 ms
5,400 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
5,400 KB
testcase_04 AC 2 ms
5,552 KB
testcase_05 AC 2 ms
5,436 KB
testcase_06 AC 2 ms
5,548 KB
testcase_07 AC 2 ms
5,468 KB
testcase_08 AC 2 ms
5,628 KB
testcase_09 AC 2 ms
5,632 KB
testcase_10 AC 2 ms
5,432 KB
testcase_11 AC 2 ms
5,536 KB
testcase_12 AC 2 ms
5,412 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1 ms
5,444 KB
testcase_15 AC 2 ms
5,436 KB
testcase_16 AC 1 ms
5,400 KB
testcase_17 AC 2 ms
5,560 KB
testcase_18 AC 2 ms
5,436 KB
testcase_19 AC 2 ms
5,564 KB
testcase_20 AC 1 ms
5,528 KB
testcase_21 AC 1 ms
5,420 KB
testcase_22 AC 1 ms
5,436 KB
testcase_23 AC 2 ms
5,404 KB
testcase_24 AC 2 ms
5,588 KB
testcase_25 AC 1 ms
4,356 KB
testcase_26 AC 2 ms
5,400 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 2 ms
5,400 KB
testcase_29 AC 2 ms
5,476 KB
testcase_30 AC 2 ms
5,500 KB
testcase_31 AC 2 ms
5,436 KB
testcase_32 AC 2 ms
5,400 KB
testcase_33 AC 26 ms
11,068 KB
testcase_34 AC 29 ms
11,488 KB
testcase_35 AC 4 ms
5,872 KB
testcase_36 AC 17 ms
8,448 KB
testcase_37 AC 24 ms
8,920 KB
testcase_38 AC 25 ms
8,972 KB
testcase_39 AC 31 ms
11,624 KB
testcase_40 AC 31 ms
11,484 KB
testcase_41 AC 30 ms
11,220 KB
testcase_42 AC 33 ms
11,524 KB
testcase_43 AC 7 ms
6,064 KB
testcase_44 AC 20 ms
8,812 KB
testcase_45 AC 28 ms
11,212 KB
testcase_46 AC 16 ms
8,268 KB
testcase_47 AC 17 ms
8,400 KB
testcase_48 AC 3 ms
5,616 KB
testcase_49 AC 33 ms
11,484 KB
testcase_50 AC 5 ms
5,696 KB
testcase_51 AC 4 ms
5,644 KB
testcase_52 AC 5 ms
5,744 KB
testcase_53 AC 33 ms
11,624 KB
testcase_54 AC 19 ms
8,704 KB
testcase_55 AC 32 ms
11,496 KB
testcase_56 AC 10 ms
5,964 KB
testcase_57 AC 33 ms
11,672 KB
testcase_58 AC 7 ms
5,768 KB
testcase_59 AC 31 ms
11,496 KB
testcase_60 AC 11 ms
6,000 KB
testcase_61 AC 35 ms
11,760 KB
testcase_62 AC 33 ms
11,596 KB
testcase_63 AC 8 ms
5,828 KB
testcase_64 AC 29 ms
11,280 KB
testcase_65 AC 13 ms
8,132 KB
testcase_66 AC 4 ms
5,720 KB
testcase_67 AC 11 ms
5,968 KB
testcase_68 AC 5 ms
5,984 KB
testcase_69 AC 27 ms
11,108 KB
testcase_70 AC 17 ms
8,408 KB
testcase_71 AC 8 ms
5,952 KB
testcase_72 AC 5 ms
5,788 KB
testcase_73 AC 12 ms
6,036 KB
testcase_74 AC 8 ms
6,048 KB
testcase_75 AC 16 ms
8,240 KB
testcase_76 AC 10 ms
5,964 KB
testcase_77 AC 27 ms
11,096 KB
testcase_78 AC 18 ms
8,532 KB
testcase_79 AC 7 ms
5,884 KB
testcase_80 AC 6 ms
5,796 KB
testcase_81 AC 6 ms
5,856 KB
testcase_82 AC 21 ms
8,812 KB
testcase_83 AC 36 ms
11,856 KB
testcase_84 AC 36 ms
11,856 KB
testcase_85 AC 36 ms
11,856 KB
testcase_86 AC 36 ms
11,740 KB
testcase_87 AC 36 ms
11,748 KB
testcase_88 AC 36 ms
11,812 KB
testcase_89 AC 37 ms
11,892 KB
testcase_90 AC 36 ms
11,856 KB
testcase_91 AC 36 ms
11,744 KB
testcase_92 AC 36 ms
11,856 KB
testcase_93 AC 2 ms
5,588 KB
testcase_94 AC 3 ms
5,488 KB
testcase_95 AC 16 ms
6,660 KB
testcase_96 AC 19 ms
7,028 KB
testcase_97 AC 17 ms
6,620 KB
testcase_98 AC 22 ms
9,332 KB
testcase_99 AC 27 ms
9,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <fstream>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <random>

using namespace std;

#define INT_MAX_VALUE 2147483647
#define LONG_LONG_MAX_VALUE 9223372036854775807
#define ll long long
#define ld long double

struct XX{
    int s;
    vector<int> t;
};

class xxGreater {
public:
    bool operator()(const XX& riLeft, const XX& riRight) const {
        //第2条件
        /*if((riLeft.s) == (riRight.s)){
            return riLeft.s < riRight.s;//<:昇順(小さいものから順番)、>:降順(大きいものから順番)
            //プライオリティキューの場合は > で、top()すると値の小さいものがとれる
        }*/
        //第1条件
        return (riLeft.s) < (riRight.s);
    }
};
struct edge{
    int ii;
    int to1;
    int to2;
    int l;
    int r;
    int w;
    int rank;
};
class rankGreater {
public:
    bool operator()(const edge& riLeft, const edge& riRight) const {
        return (riLeft.rank) > (riRight.rank);
    }
};
//map<long long,long long> prime_f(long long n){
//    map<long long,long long>res;
//    for(int i=2;i*i<=n;i++){
//        while(n%i==0){
//            ++res[i];
//            n/=i;
//        }
//    }
//    if(n!=1)res[n]=1;
//    return res;
//}

//int n;
////int dat[2*10000000];
////int dat2[2*10000000];
//int dat[10];
//int dat2[10];
//
//void init(int n_){
//    n=1;
//    while(n<n_)n*=2;
//    for(int i=0;i<2*n-1;i++){
//        dat[i]=0;
//        dat2[i]=0;
//    }
//}
//
//void initset(int k,int a){
//    k+=n-1;
//    dat[k]=a;
//    while(k>0){
//        k=(k-1)/2;
//        dat[k]=dat[k*2+1]+dat[k*2+2];
//    }
//}
//
////[a,b)の間を[l,r]区間で比較しアップデート
////引数のindexに注意
////nは固定。initで計算すみ
////update2(L[i],R[i]+1,0,0,n,D[i]);
//void update2(int a,int b,int k,int l,int r,int v){//v更新値、区間は0-index
//    if(r<=a || b<=l)return;
//    if(a<=l && r<=b){
//        dat[k]+=dat2[k];
//        if(r-l>1){
//            dat2[k*2+1]+=dat2[k]/2;
//            dat2[k*2+1]+=dat2[k]/2;
//        }
//        dat2[k]=v*(r-l);
//        return;
//    }else{
//        update2(a,b,k*2+1,l,(l+r)/2,v);
//        update2(a,b,k*2+2,(l+r)/2,r,v);
//        return;
//    }
//}
//
//int query(int a,int b,int k,int l,int r){
//    if(r<=a || b<=l)return 0;
//    if(a<=l && r<=b){
//        dat[k]+=dat2[k];
//        if(r-l>1){
//            dat2[k*2+1]+=dat2[k]/2;
//            dat2[k*2+1]+=dat2[k]/2;
//        }
//        dat2[k]=0;
//        return dat[k];
//    }
//    else{
//        int vl=query(a,b,k*2+1,l,(l+r)/2);
//        int vr=query(a,b,k*2+2,(l+r)/2,r);
//        return vl+vr;
//    }
//}


edge G[2*10000000];
//edge G[2*1000];
int aa[2*10000000];
//int aa[2*1000];

int main(int argc, const char * argv[])
{
    //scanf("%s",S);
    //scanf("%d",&N);
    //scanf("%lld %lld",&target1,&target2);
    //sscanf(tmp.c_str(),"%dd%d%d",&time[i], &dice[i], &z[i]);
    //getline(cin, target);
    //ifstream ifs("3.txt");//テスト用
    //ifs >> a;
    //ここから
    
    //入力高速化
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N;
    cin >> N;
    vector<ll> a;
    for(int i=0;i<N;i++){
        ll tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    if(N==1){
        cout << "First" << endl;
        return 0;
    }
    ll wa[100000];
    for(int i=0;i<N;i++){
        if(i==0){
            wa[i]=a[i];
        }else{
            wa[i]=a[i]+wa[i-1];
        }
    }

    struct P{
        int l;
        int r;
        int w;
    };
    
    


    queue<int> que;
    que.push(0);

    G[0].l=0;
    G[0].r=N-1;
    G[0].rank=0;
    G[0].ii=0;

    int index=1;
    while(!que.empty()){
        edge tmp=G[que.front()];
        ll avg;
        if(tmp.l>=tmp.r){
            que.pop();
            continue;
        }
        if(a[tmp.l]==a[tmp.r]){
            que.pop();
            continue;
        }
        if(tmp.l-1>=0){
            avg=(wa[tmp.r]-wa[tmp.l-1])/(tmp.r-(tmp.l-1));
            if((wa[tmp.r]-wa[tmp.l-1])%(tmp.r-(tmp.l-1))>0){
                avg++;
            }
        }else{
            avg=wa[tmp.r]/(tmp.r+1);
            if(wa[tmp.r]%(tmp.r+1)>0){
                avg++;
            }
        }
        int mid=(int)(lower_bound(a.begin(),a.end(),avg)-a.begin());
        if(tmp.l<=mid-1){
            G[que.front()].to1=index;
            G[index].l=tmp.l;
            G[index].r=mid-1;
            G[index].rank=G[que.front()].rank+1;
            G[index].ii=index;
            if(mid-1<0)G[index].r=0;
            
            que.push(index);
            index++;
        }else{
            G[que.front()].to1=-1;
        }
        if(mid<=tmp.r){
            G[que.front()].to2=index;
            G[index].l=mid;
            G[index].r=tmp.r;
            G[index].rank=G[que.front()].rank+1;
            G[index].ii=index;

            que.push(index);
            index++;
        }else{
            G[que.front()].to2=-1;
        }
        que.pop();
    }
    //rankでソート
    sort(G,G+index,rankGreater());
    
    for(int i=0;i<index;i++){
        aa[G[i].ii]=i;
    }
    for(int i=0;i<index;i++){
        if(G[i].r==G[i].l || a[G[i].r]==a[G[i].l]){
            if(G[i].rank%2==0){
                G[i].w=1;
            }else{
                G[i].w=2;
            }
        }else{
            if(G[i].rank%2==0){
                if((G[i].to1!=0 && G[aa[G[i].to1]].w==1) || (G[i].to1!=0 && G[aa[G[i].to2]].w==1)){
                    G[i].w=1;
                }else{
                    G[i].w=2;
                }
            }else{
                if((G[i].to1!=0 && G[aa[G[i].to1]].w==2) || (G[i].to2!=0 && G[aa[G[i].to2]].w==2)){
                    G[i].w=2;
                }else{
                    G[i].w=1;
                }
            }
        }
    }
    if(G[index-1].w==1){
        cout << "First" << endl;
    }else{
        cout << "Second" << endl;
    }
    
    
    
    //ここまで
    //cout << "ans" << endl;
    //printf("%.0f\n",ans);//小数点以下表示なし
    //printf("%.7f\n",p);
    
    return 0;
}
0