結果

問題 No.761 平均値ゲーム
ユーザー butsurizukibutsurizuki
提出日時 2018-12-07 04:48:39
言語 C
(gcc 12.3.0)
結果
RE  
実行時間 -
コード長 2,982 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 30,904 KB
実行使用メモリ 16,984 KB
最終ジャッジ日時 2023-10-12 03:40:52
合計ジャッジ時間 7,426 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
12,160 KB
testcase_01 AC 3 ms
7,876 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 3 ms
7,864 KB
testcase_04 AC 3 ms
7,872 KB
testcase_05 AC 2 ms
7,864 KB
testcase_06 AC 2 ms
7,948 KB
testcase_07 AC 3 ms
7,892 KB
testcase_08 AC 2 ms
7,816 KB
testcase_09 AC 3 ms
7,892 KB
testcase_10 AC 3 ms
7,928 KB
testcase_11 AC 3 ms
7,848 KB
testcase_12 AC 2 ms
7,884 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 3 ms
7,948 KB
testcase_15 AC 2 ms
7,872 KB
testcase_16 AC 2 ms
7,816 KB
testcase_17 AC 3 ms
7,808 KB
testcase_18 AC 2 ms
7,912 KB
testcase_19 AC 2 ms
7,880 KB
testcase_20 AC 2 ms
7,924 KB
testcase_21 AC 3 ms
7,812 KB
testcase_22 AC 2 ms
7,876 KB
testcase_23 AC 3 ms
7,924 KB
testcase_24 AC 2 ms
7,804 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 2 ms
7,804 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 3 ms
7,868 KB
testcase_29 AC 2 ms
7,876 KB
testcase_30 AC 3 ms
7,812 KB
testcase_31 AC 3 ms
7,864 KB
testcase_32 AC 2 ms
7,844 KB
testcase_33 RE -
testcase_34 RE -
testcase_35 AC 8 ms
8,588 KB
testcase_36 WA -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 AC 17 ms
9,336 KB
testcase_44 TLE -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
testcase_89 -- -
testcase_90 -- -
testcase_91 -- -
testcase_92 -- -
testcase_93 -- -
testcase_94 -- -
testcase_95 -- -
testcase_96 -- -
testcase_97 -- -
testcase_98 -- -
testcase_99 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>

#define size 131072
#define llinf 4154118101919364364

long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}

typedef struct{
long long val;
long long node;
}sd;

int sdsortfnc(const void *a,const void *b){
if(((sd*)a)->val > ((sd*)b)->val){return -1;}
if(((sd*)a)->val < ((sd*)b)->val){return 1;}
return 0;
}

typedef struct{
    long long st;
    long long fi;
}rs;

typedef struct{
    long long st;
    long long kz;
}mkj;

int sortfnc(const void *a,const void *b){
if(((rs*)a)->st == ((rs*)b)->st){return 0;}
if(((rs*)a)->st < ((rs*)b)->st){return -1;}
return 1;
}

void makemkj(rs g[],mkj x[],long long n){
    long long i,ms=0,nst=g[0].st;
    for(i=1;i<n;i++){
        if(g[i].st!=g[i-1].st){
            x[nst].kz=i-ms;
            x[nst].st=ms;
            nst=g[i].st;ms=i;
        }
    }
    x[nst].kz=n-ms;
    x[nst].st=ms;
}

long long search(long long x,long long a[],long long n){
    long long st=0,fi=n-1,te;
    while(st<=fi){
        te=(st+fi)/2;
        if(a[te]<x){st=te+1;}else{fi=te-1;}
    }
    return st;
}

long long vid=0,eid=0,color[size]={0};
long long n,a[size],rw[size]={0};

void grep(long long s,long long f,long long pid,rs g[]){
  long long nv=vid,te,pt;
  vid++;
  if(pid!=-1){
    g[eid].st=pid;
    g[eid].fi=nv;
    eid++;
    g[eid].fi=pid;
    g[eid].st=nv;
    eid++;
  }
  if(a[s]==a[f]){return;}
  te=llceil(rw[f]-rw[s-1],f-s+1);
  pt=search(te,&a[s],f-s+1);
  pt+=s;
  //printf("%lld:%lld %lld %lld %lld\n",nv,s,f,te,pt);
  grep(s,pt-1,nv,g);
  grep(pt,f,nv,g);
  return;
}

long long dist[size];
void dfs(long long t,long long l,rs g[],mkj x[]){
  long long i;
  if(dist[t]<=l){return;}
  dist[t]=l;
  for(i=x[t].st;i<x[t].st+x[t].kz;i++){
    dfs(g[i].fi,l+1,g,x);
  }
}

int main(void){
    long long i,j,fl,nv,fn=0,sn=0;
    rs g[size];
    mkj x[size];
    sd dat[size];
    scanf("%lld",&n);
    for(i=1;i<=n;i++){
      scanf("%lld",&a[i]);
      rw[i]=rw[i-1]+a[i];
    }
    if(n==1){
      printf("First\n");
      return 0;
    }
    //printf("ok\n");
    grep(1,n,-1,g);
    //printf("ok\n");
    qsort(g,eid,sizeof(g[0]),sortfnc);
    //printf("ok\n");
    makemkj(g,x,eid);
    //printf("ok\n");
    for(i=0;i<vid;i++){
      dist[i]=llinf;
    }
    dfs(0,0,g,x);
    for(i=0;i<vid;i++){
      dat[i].val=dist[i];
      dat[i].node=i;
    }
    qsort(dat,vid,sizeof(dat[0]),sdsortfnc);
    for(i=0;i<vid;i++){
      fl=0;
      nv=dat[i].node;
      for(j=x[nv].st;j<x[nv].st+x[nv].kz;j++){
        if(dist[g[j].fi]<dist[nv]){continue;}
        fl|=color[g[j].fi];
      }
      if(fl==0 || fl==3){
        color[nv]=(dist[nv]%2)+1;
      }
      else{
        color[nv]=fl;
      }
      if(color[nv]==1){fn++;}else{sn++;}
    }
    //printf("<%lld %lld>\n",fn,sn);
    for(i=0;i<vid;i++){
      //printf("[%lld:%lld]\n",i,color[i]);
    }
    if(color[0]==1){
      printf("First\n");
    }
    else{
      printf("Second\n");
    }
    return 0;
}
0