結果

問題 No.1290 Addition and Subtraction Operation
ユーザー tails
提出日時 2020-11-24 20:19:37
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,232 bytes
コンパイル時間 513 ms
コンパイル使用メモリ 31,744 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-23 18:47:09
合計ジャッジ時間 4,578 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 85
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:38:1: warning: return type defaults to 'int' [-Wimplicit-int]
   38 | main(){
      | ^~~~
main.c: In function 'main':
main.c:78:9: warning: implicit declaration of function 'write' [-Wimplicit-function-declaration]
   78 |         write(1,bp==bs+(n+1)?"YES":"NO ",3);
      |         ^~~~~
main.c:79:9: warning: implicit declaration of function '_exit'; did you mean '_Exit'? [-Wimplicit-function-declaration]
   79 |         _exit(0);
      |         ^~~~~
      |         _Exit

ソースコード

diff #

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

char*mmap();
#define RD(v) int v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;}
#define RDL(v) long v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;}

#define UFSIZE 100001
int ufbuf[UFSIZE];
void uf_init(){
	for(int i=0;i<UFSIZE;++i){
		ufbuf[i]=-1;
	}
}
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(ufbuf[a]<ufbuf[b]){
			ufbuf[a]+=ufbuf[b];
			ufbuf[b]=a;
		}else{
			ufbuf[b]+=ufbuf[a];
			ufbuf[a]=b;
		}
	}
}

long bs[100002];

main(){
	uf_init();
	char*rp=mmap(0l,12l*300003,1,2,0,0ll);
	RD(n);
	RD(m);
	long t=0;
	for(int i=0;i<n;++i){
		int neg=i&1;
		if(*rp=='-'){
			neg^=1;
			++rp;
		}
		RDL(b);
		b=neg?-b:b;
		bs[i]=b-t;
		t=b;
	}
	bs[n]=-t;
	for(int j=0;j<m;++j){
		RD(l);
		RD(r);
		l=uf_root(l-1);
		r=uf_root(r);
		if(l!=r){
			if(ufbuf[l]<ufbuf[r]){
				ufbuf[l]+=ufbuf[r];
				ufbuf[r]=l;
				bs[l]+=bs[r];
				bs[r]=0;
			}else{
				ufbuf[r]+=ufbuf[l];
				ufbuf[l]=r;
				bs[r]+=bs[l];
				bs[l]=0;
			}
		}
	}
	bs[n+1]=1;
	long*bp=bs;
	while(!*bp)++bp;
	write(1,bp==bs+(n+1)?"YES":"NO ",3);
	_exit(0);
}
0