結果

問題 No.2740 Old Maid
ユーザー tailstails
提出日時 2024-04-22 10:06:11
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 845 bytes
コンパイル時間 827 ms
コンパイル使用メモリ 24,320 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2024-04-22 10:06:18
合計ジャッジ時間 6,677 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
5,888 KB
testcase_01 AC 8 ms
5,888 KB
testcase_02 AC 8 ms
5,888 KB
testcase_03 AC 7 ms
5,888 KB
testcase_04 AC 7 ms
5,760 KB
testcase_05 AC 7 ms
5,888 KB
testcase_06 AC 7 ms
5,888 KB
testcase_07 AC 7 ms
5,888 KB
testcase_08 AC 8 ms
5,888 KB
testcase_09 AC 7 ms
5,888 KB
testcase_10 AC 7 ms
5,888 KB
testcase_11 AC 6 ms
5,888 KB
testcase_12 AC 7 ms
5,376 KB
testcase_13 AC 8 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 5 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 7 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 8 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 5 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 10 ms
5,376 KB
testcase_26 AC 0 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 5 ms
5,376 KB
testcase_29 AC 5 ms
5,376 KB
testcase_30 AC 0 ms
5,376 KB
testcase_31 AC 11 ms
5,888 KB
testcase_32 AC 3 ms
5,376 KB
testcase_33 AC 10 ms
5,504 KB
testcase_34 AC 5 ms
5,376 KB
testcase_35 AC 3 ms
5,376 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 4 ms
5,376 KB
testcase_38 AC 3 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 6 ms
5,376 KB
testcase_41 AC 9 ms
5,376 KB
testcase_42 AC 1 ms
5,376 KB
testcase_43 AC 1 ms
5,376 KB
testcase_44 AC 1 ms
5,376 KB
testcase_45 AC 1 ms
5,376 KB
testcase_46 AC 0 ms
5,376 KB
testcase_47 AC 1 ms
5,376 KB
testcase_48 AC 1 ms
5,376 KB
testcase_49 AC 0 ms
5,376 KB
testcase_50 AC 1 ms
5,376 KB
testcase_51 AC 1 ms
5,376 KB
testcase_52 AC 0 ms
5,376 KB
testcase_53 AC 0 ms
5,376 KB
testcase_54 AC 1 ms
5,376 KB
testcase_55 AC 0 ms
5,376 KB
testcase_56 AC 0 ms
5,376 KB
testcase_57 AC 1 ms
5,376 KB
testcase_58 AC 0 ms
5,376 KB
testcase_59 AC 1 ms
5,376 KB
testcase_60 AC 0 ms
5,376 KB
testcase_61 AC 0 ms
5,376 KB
testcase_62 AC 0 ms
5,376 KB
testcase_63 AC 0 ms
5,376 KB
testcase_64 AC 0 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘f2’:
main.c:42:9: warning: implicit declaration of function ‘write’ [-Wimplicit-function-declaration]
   42 |         write(1,wbuf,wp-wbuf);
      |         ^~~~~
main.c: In function ‘main’:
main.c:48:9: warning: implicit declaration of function ‘_exit’ [-Wimplicit-function-declaration]
   48 |         _exit(0);
      |         ^~~~~
main.c:48:9: warning: incompatible implicit declaration of built-in function ‘_exit’ [-Wbuiltin-declaration-mismatch]

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")

#define rd_init() char*rp=({char*mmap();mmap(0l,1l<<25,1,2,0,0ll);})
#define rd() ({int _v=0,_c;while(_c=*rp++-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 reps(v,s,e) for(typeof(e) v=s;v<e;++v)

char wbuf[1<<25];
int n;
int p[200000];
int v[200001];
int s[200001];

void f1(){
	rd_init();
	n=rd();
	rep(i,n){
		p[i]=rd();
		v[p[i]]=i;
	}
}

void f2(){
	char*wp=wbuf;
	reps(a,1,n+1){
		int i=v[a];
		if(!s[i]){
			int j,k;
			for(j=i+1;s[j];j=s[j]);
			for(k=i+1;s[k];k=s[k])s[k]=j;
			if(j<n){
				wt(a);
				*wp++=' ';
				wt(p[j]);
				*wp++=' ';
				s[i]=s[j]=j+1;
			}
		}
	}
	write(1,wbuf,wp-wbuf);
}

int main(){
	f1();
	f2();
	_exit(0);
}
0