結果

問題 No.761 平均値ゲーム
ユーザー butsurizukibutsurizuki
提出日時 2018-12-07 03:31:12
言語 C
(gcc 12.3.0)
結果
RE  
実行時間 -
コード長 2,978 bytes
コンパイル時間 1,237 ms
コンパイル使用メモリ 30,816 KB
実行使用メモリ 4,480 KB
最終ジャッジ日時 2023-10-12 03:40:21
合計ジャッジ時間 15,136 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

#define size 64
#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