結果

問題 No.2967 Nana's Plus Permutation Game
ユーザー tailstails
提出日時 2024-12-03 16:47:23
言語 C90
(gcc 11.4.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
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
25,208 KB
testcase_01 AC 143 ms
24,824 KB
testcase_02 AC 92 ms
24,824 KB
testcase_03 AC 103 ms
25,204 KB
testcase_04 AC 135 ms
25,208 KB
testcase_05 AC 133 ms
24,568 KB
testcase_06 AC 123 ms
25,064 KB
testcase_07 AC 144 ms
24,820 KB
testcase_08 AC 82 ms
25,208 KB
testcase_09 AC 136 ms
25,208 KB
testcase_10 AC 133 ms
24,824 KB
testcase_11 AC 81 ms
25,208 KB
testcase_12 AC 88 ms
24,824 KB
testcase_13 AC 160 ms
24,568 KB
testcase_14 AC 150 ms
24,824 KB
testcase_15 AC 119 ms
25,464 KB
testcase_16 AC 96 ms
24,824 KB
testcase_17 AC 133 ms
24,824 KB
testcase_18 AC 112 ms
25,336 KB
testcase_19 AC 83 ms
24,824 KB
testcase_20 AC 110 ms
25,208 KB
testcase_21 AC 178 ms
24,824 KB
testcase_22 AC 179 ms
25,452 KB
testcase_23 AC 168 ms
24,824 KB
testcase_24 AC 183 ms
24,568 KB
testcase_25 AC 179 ms
24,568 KB
testcase_26 AC 198 ms
24,568 KB
testcase_27 AC 160 ms
24,824 KB
testcase_28 AC 215 ms
24,824 KB
testcase_29 AC 199 ms
24,824 KB
testcase_30 AC 210 ms
25,208 KB
testcase_31 AC 178 ms
24,824 KB
testcase_32 AC 160 ms
25,208 KB
testcase_33 AC 159 ms
24,824 KB
testcase_34 AC 148 ms
24,824 KB
testcase_35 AC 179 ms
24,568 KB
testcase_36 AC 160 ms
25,196 KB
testcase_37 AC 210 ms
24,568 KB
testcase_38 AC 180 ms
24,824 KB
testcase_39 AC 178 ms
24,568 KB
testcase_40 AC 179 ms
25,208 KB
testcase_41 AC 223 ms
25,196 KB
testcase_42 AC 219 ms
25,196 KB
testcase_43 AC 199 ms
24,940 KB
testcase_44 AC 240 ms
25,196 KB
testcase_45 AC 223 ms
24,812 KB
testcase_46 AC 250 ms
24,940 KB
testcase_47 AC 250 ms
24,812 KB
testcase_48 AC 230 ms
24,556 KB
testcase_49 AC 210 ms
24,556 KB
testcase_50 AC 219 ms
25,180 KB
testcase_51 AC 209 ms
24,940 KB
testcase_52 AC 235 ms
24,940 KB
testcase_53 AC 198 ms
24,940 KB
testcase_54 AC 211 ms
25,196 KB
testcase_55 AC 204 ms
24,940 KB
testcase_56 AC 251 ms
24,940 KB
testcase_57 AC 230 ms
24,812 KB
testcase_58 AC 231 ms
24,812 KB
testcase_59 AC 230 ms
24,940 KB
testcase_60 AC 231 ms
25,196 KB
testcase_61 AC 88 ms
25,196 KB
testcase_62 AC 80 ms
25,196 KB
testcase_63 AC 81 ms
24,812 KB
testcase_64 AC 80 ms
24,940 KB
testcase_65 AC 81 ms
24,556 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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]

ソースコード

diff #

#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);
}
0