結果

問題 No.1433 Two color sequence
ユーザー tails
提出日時 2021-03-19 21:58:26
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 794 bytes
コンパイル時間 929 ms
コンパイル使用メモリ 30,848 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-18 22:14:02
合計ジャッジ時間 2,085 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:11:1: warning: return type defaults to 'int' [-Wimplicit-int]
   11 | main(){
      | ^~~~
main.c: In function 'main':
main.c:29:9: warning: implicit declaration of function 'write' [-Wimplicit-function-declaration]
   29 |         write(1,wbuf,wp-wbuf);
      |         ^~~~~
main.c:30:9: warning: implicit declaration of function '_exit'; did you mean '_Exit'? [-Wimplicit-function-declaration]
   30 |         _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 WTHI(v) {long _z=v,_n=0,_d=0;while(++_n,_d=_d<<8|0x30|_z%10,_z/=10);*(long*)wp=_d;wp+=_n;}
#define WTLO(v) {long _z=v,_n=8,_d=0;while(_d=_d<<8|0x30|_z%10,_z/=10,--_n);*(long*)wp=_d;wp+=8;}
#define WT(v) if(v>=100000000){WTHI(v/100000000);WTLO(v);}else{WTHI(v);}

main(){
	char*rp=mmap(0l,1l<<28,1,2,0,0ll);
	RD(n);
	char*cp=rp;
	rp+=n+1;
	long s=0,min=0,max=0,a0=0,a1=0;
	for(int i=0;i<n;++i){
		int neg=*cp++=='B'^(*rp=='-'&&++rp);
		RD(a);
		s+=neg?-a:a;
		if(min>s) min=s;
		if(max<s) max=s;
		if(a0<max-min) a0=max-min;
		if(a1<min-max) a1=min-max;
	}
	long v=a0>=a1?a0:a1;
	char wbuf[16],*wp=wbuf;
	WT(v);
	write(1,wbuf,wp-wbuf);
	_exit(0);
}
0