結果
問題 | No.2967 Nana's Plus Permutation Game |
ユーザー |
![]() |
提出日時 | 2024-12-03 16:47:23 |
言語 | C90 (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 251 ms / 2,000 ms |
コード長 | 1,472 bytes |
コンパイル時間 | 266 ms |
コンパイル使用メモリ | 26,752 KB |
実行使用メモリ | 25,464 KB |
平均クエリ数 | 4171.09 |
最終ジャッジ日時 | 2024-12-03 16:47:40 |
合計ジャッジ時間 | 15,166 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 65 |
コンパイルメッセージ
main.c: In function ‘main’: main.c:5:37: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration] 5 | #define rd_getc() ({if(rpos>=rend){usleep(10000);rpos=0;rend=read(0,rbuf,4096);}rbuf[rpos++];}) | ^~~~~~ main.c:6:37: note: in expansion of macro ‘rd_getc’ 6 | #define rd() ({int _v=0,_c;while(_c=rd_getc()-48,_c>=0)_v=_v*10+_c;_v;}) | ^~~~~~~ main.c:18:15: note: in expansion of macro ‘rd’ 18 | int n=rd(); | ^~ main.c:5:63: warning: implicit declaration of function ‘read’ [-Wimplicit-function-declaration] 5 | #define rd_getc() ({if(rpos>=rend){usleep(10000);rpos=0;rend=read(0,rbuf,4096);}rbuf[rpos++];}) | ^~~~ main.c:6:37: note: in expansion of macro ‘rd_getc’ 6 | #define rd() ({int _v=0,_c;while(_c=rd_getc()-48,_c>=0)_v=_v*10+_c;_v;}) | ^~~~~~~ main.c:18:15: note: in expansion of macro ‘rd’ 18 | int n=rd(); | ^~ main.c:29:17: warning: implicit declaration of function ‘write’ [-Wimplicit-function-declaration] 29 | write(1,wbuf,wp-wbuf); | ^~~~~ main.c:94:9: warning: implicit declaration of function ‘_exit’ [-Wimplicit-function-declaration] 94 | _exit(0); | ^~~~~ main.c:94:9: warning: incompatible implicit declaration of built-in function ‘_exit’ [-Wbuiltin-declaration-mismatch]
ソースコード
#pragma GCC optimize("Ofast") #pragma GCC target("avx2") #define rd_peekc() ({if(rpos>=rend){usleep(10000);rpos=0;rend=read(0,rbuf,4096);}rbuf[rpos];}) #define rd_getc() ({if(rpos>=rend){usleep(10000);rpos=0;rend=read(0,rbuf,4096);}rbuf[rpos++];}) #define rd() ({int _v=0,_c;while(_c=rd_getc()-48,_c>=0)_v=_v*10+_c;_v;}) #define wt(v) {unsigned _z=v,_n=0;long _d=0;while(++_n,_d=_d<<8|0x30|_z%10,_z/=10);*(long*)wp=_d;wp+=_n;} #define rep(v,e) for(typeof(e)v=0;v<e;++v) #define rrep(v,e) for(typeof(e)v=e;v--;) char wbuf[1<<25]; char rbuf[4096]; int rpos,rend; int a[5000]; int b[5000]; int main(){ int n=rd(); { char*wp=wbuf; rep(i,n){ *wp++='1'; *wp++=' '; wt(i+1); *wp++=' '; wt(i+1); *wp++='\n'; } write(1,wbuf,wp-wbuf); } rep(i,n){ if(rd_peekc()=='-'){ rd_getc(); rd_getc(); rd_getc(); a[i]=-1; }else{ a[i]=rd()-1; } } int x=({ int x=0; int b=0; rep(i,n){ int j=i; int c=0; while(j=a[j],j>=0){ ++c; } if(c>=b){ b=c; x=i; } } x; }); { char*wp=wbuf; rep(i,n){ *wp++='1'; *wp++=' '; wt(x+1); *wp++=' '; wt(i+1); *wp++='\n'; } write(1,wbuf,wp-wbuf); } int y=0; rep(i,n){ if(rd_peekc()=='-'){ rd_getc(); rd_getc(); rd_getc(); y=i; }else{ a[rd()-1]=i; } } rrep(i,n){ b[y]=i; y=a[y]; } { char*wp=wbuf; *wp++='2'; rep(i,n){ *wp++=' '; wt(b[i]+1); } *wp++='\n'; write(1,wbuf,wp-wbuf); } _exit(0); }