結果

問題 No.545 ママの大事な二人の子供
ユーザー tailstails
提出日時 2021-05-13 14:44:57
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,929 bytes
コンパイル時間 713 ms
コンパイル使用メモリ 34,788 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 08:40:11
合計ジャッジ時間 1,849 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 6 ms
4,348 KB
testcase_23 AC 13 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 9 ms
4,348 KB
testcase_26 AC 12 ms
4,348 KB
testcase_27 AC 5 ms
4,348 KB
testcase_28 AC 13 ms
4,348 KB
testcase_29 AC 7 ms
4,348 KB
testcase_30 AC 11 ms
4,348 KB
testcase_31 AC 9 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:50:1: warning: return type defaults to 'int' [-Wimplicit-int]
   50 | main(){
      | ^~~~
main.c: In function 'main':
main.c:111:9: warning: implicit declaration of function 'write' [-Wimplicit-function-declaration]
  111 |         write(1,wbuf,wp-wbuf);
      |         ^~~~~
main.c:112:9: warning: implicit declaration of function '_exit'; did you mean '_Exit'? [-Wimplicit-function-declaration]
  112 |         _exit(0);
      |         ^~~~~
      |         _Exit

ソースコード

diff #

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

char*mmap();
#define rd_skip() while(*rp++>=48)
#define rd(v) int v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;}
#define rd_long(v) long 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);}

#define rep(v,e) for(int v=0;v<e;++v)
#define chmin(v,a) (v=v<=a?v:a)

void radix_sort_aux(unsigned long*a,unsigned long*b,int n){
	int c[256];
	for(int i=0;i<256;++i){
		c[i]=0;
	}
	for(int i=0;i<n;++i){
		++c[a[i]&255];
	}
	int t=0;
	for(int i=0;i<256;++i){
		int u=c[i];
		c[i]=t;
		t+=u;
	}
	for(int i=0;i<n;++i){
		b[c[a[i]&255]++]=a[i]>>8|a[i]<<56;
	}
}

long rsbuf[1<<16];

void radix_sort(unsigned long*a,int n){
	radix_sort_aux(a,rsbuf,n);
	radix_sort_aux(rsbuf,a,n);
	radix_sort_aux(a,rsbuf,n);
	radix_sort_aux(rsbuf,a,n);
	radix_sort_aux(a,rsbuf,n);
	for(int i=0;i<n;++i){
		a[i]=rsbuf[i]>>24;
	}
}

long d1[1<<16],d2[1<<16];

main(){
	char*rp=mmap(0l,1l<<28,1,2,0,0ll);
	rd(n);
	int n1=n>>1;
	int n2=n-n1;

	d1[0]=1l<<37;
	int k1=1;
	rep(i,n1){
		rd_long(a);
		rep(j,k1){
			d1[j+k1]=d1[j]+a;
		}
		rd_long(b);
		rep(j,k1){
			d1[j]-=b;
		}
		k1<<=1;
	}
	radix_sort(d1,k1);

	d2[0]=1l<<37;
	int k2=1;
	rep(i,n2){
		rd_long(a);
		rep(j,k2){
			d2[j+k2]=d2[j]+a;
		}
		rd_long(b);
		rep(j,k2){
			d2[j]-=b;
		}
		k2<<=1;
	}

	long r=1l<<62;
	rep(i,k2){
		long d=d2[i];
		int lo=0,hi=k1-1;
		while(lo+1<hi){
			int m=lo+hi>>1;
			if(d+d1[m]-(1l<<38)>=0){
				hi=m;
			}else{
				lo=m;
			}
		}
		{
			long a=d+d1[lo]-(1l<<38);
			a=a>=0?a:-a;
			chmin(r,a);
		}
		{
			long a=d+d1[hi]-(1l<<38);
			a=a>=0?a:-a;
			chmin(r,a);
		}
	}

	char wbuf[32],*wp=wbuf;
	wt(r);
	write(1,wbuf,wp-wbuf);
	_exit(0);
}
0