結果

問題 No.1734 Decreasing Elements
ユーザー tailstails
提出日時 2021-11-17 16:15:23
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 9 ms / 3,000 ms
コード長 1,171 bytes
コンパイル時間 1,075 ms
コンパイル使用メモリ 31,632 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 04:23:34
合計ジャッジ時間 3,071 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 6 ms
4,376 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 6 ms
4,380 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 9 ms
4,380 KB
testcase_18 AC 9 ms
4,376 KB
testcase_19 AC 6 ms
4,376 KB
testcase_20 AC 6 ms
4,380 KB
testcase_21 AC 6 ms
4,380 KB
testcase_22 AC 6 ms
4,376 KB
testcase_23 AC 6 ms
4,380 KB
testcase_24 AC 7 ms
4,384 KB
testcase_25 AC 6 ms
4,380 KB
testcase_26 AC 6 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘f2’ 内:
main.c:69:9: 警告: 関数 ‘write’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   69 |         write(1,wp,wbuf+sizeof wbuf-wp);
      |         ^~~~~
main.c:70:9: 警告: implicit declaration of function ‘_exit’; did you mean ‘_Exit’? [-Wimplicit-function-declaration]
   70 |         _exit(0);
      |         ^~~~~
      |         _Exit
main.c: トップレベル:
main.c:73:1: 警告: 戻り値の型をデフォルトの ‘int’ にします [-Wimplicit-int]
   73 | main(){
      | ^~~~

ソースコード

diff #

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

#define rd_skip() while(*rp++>=48)
#define rd(v) long v=0;{long _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;}
#define wt(v) {long _z=v;do*--wp=_z%10+48;while(_z/=10);}

#define UFSIZE 200001
int ufbuf[UFSIZE];
int ufval[UFSIZE];
void uf_init(){
	for(int i=0;i<UFSIZE;++i){
		ufbuf[i]=-1;
		ufval[i]=i;
	}
}
int uf_root(int a){
	int b;
	int t=a;
	while(b=ufbuf[t],b>=0) t=b;
	while(b=ufbuf[a],b>=0) ufbuf[a]=t,a=b;
	return t;
}
void uf_unite(int a,int b){
	a=uf_root(a);
	b=uf_root(b);
	if(a!=b){
		if(1){
			ufbuf[a]+=ufbuf[b];
			ufbuf[b]=a;
		}else{
			ufbuf[b]+=ufbuf[a];
			ufbuf[a]=b;
			ufval[b]=ufval[a];
		}
	}
}


long f1(){
	char*mmap();
	char*rp=mmap(0l,1l<<25,1,2,0,0ll);
	rd_skip();
	long lo=0;
	long hi=200001;
	long z=0;
	while(*rp){
		rd(a);
		long x=ufval[uf_root(a)];
		if(x-lo){
			if(x*2<lo+hi){
				for(long y=x-lo;y--;){
					uf_unite(x++,lo++);
				}
			}else{
				for(long y=hi-x;y--;){
					uf_unite(y+lo,--hi);
				}
			}
			++z;
		}
	}
	return z;
}

void f2(long z){
	char wbuf[64],*wp=wbuf+sizeof wbuf;
	wt(z);
	write(1,wp,wbuf+sizeof wbuf-wp);
	_exit(0);
}

main(){
	uf_init();
	f2(f1());
}
0