結果

問題 No.2370 He ate many cakes
ユーザー tailstails
提出日時 2023-07-04 10:51:18
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,518 bytes
コンパイル時間 396 ms
コンパイル使用メモリ 30,924 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 08:38:44
合計ジャッジ時間 1,402 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 0 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 5 ms
4,376 KB
testcase_04 AC 0 ms
4,376 KB
testcase_05 AC 0 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 0 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 0 ms
4,376 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 5 ms
4,380 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 0 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:7:59: warning: implicit declaration of function ‘write’ [-Wimplicit-function-declaration]
 #define wt1(v) ({char wbuf[64],*wp=wbuf+sizeof wbuf;wt(v);write(1,wp,wbuf+sizeof wbuf-wp);})
                                                           ^~~~~
main.c:85:2: note: in expansion of macro ‘wt1’
  wt1(lo+o);
  ^~~
main.c:86:2: warning: implicit declaration of function ‘_exit’ [-Wimplicit-function-declaration]
  _exit(0);
  ^~~~~
main.c:86:2: warning: incompatible implicit declaration of built-in function ‘_exit’

ソースコード

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() ({long _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;})
#define wt(v) ({ulong _z=v;int neg=(long)_z<0?_z=-_z,1:0;do*--wp=_z%10+48;while(_z/=10);if(neg)*--wp='-';})
#define wt1(v) ({char wbuf[64],*wp=wbuf+sizeof wbuf;wt(v);write(1,wp,wbuf+sizeof wbuf-wp);})
#define rep(v,e) for(typeof(e) v=0;v<e;++v)

typedef unsigned long ulong;

void sort_aux(ulong*a,ulong*b,int n,int p){
	int c[512];
	for(int i=0;i<512;++i){
		c[i]=0;
	}
	for(int i=0;i<n;++i){
		++c[a[i]&511];
	}
	int t=0;
	for(int i=0;i<512;++i){
		int u=c[i];
		c[i]=t;
		t+=u;
	}
	if(p==0){
		for(int i=0;i<n;++i){
			b[c[a[i]&511]++]=a[i]>>9|a[i]<<55;
		}
	}else{
		for(int i=0;i<n;++i){
			b[c[a[i]&511]++]=a[i]>>37|a[i]<<27;
		}
	}
}

void sort(ulong*a,int n){
	static ulong b[1<<15];
	sort_aux(a,b,n,0);
	sort_aux(b,a,n,0);
	sort_aux(a,b,n,0);
	sort_aux(b,a,n,1);
}

long v[2][1<<15];
int vn[2];

int main(){
	rd_init();
	int n=rd();
	int k=rd();
	long o=0;
	vn[0]=1;
	vn[1]=1;
	rep(i,n){
		int neg=*rp=='-'&&++rp;
		long a=rd();
		if(neg){
			o-=a;
		}
		rep(j,vn[i&1]){
			v[i&1][vn[i&1]+j]=v[i&1][j]+a;
		}
		vn[i&1]<<=1;
	}
	sort(v[0],vn[0]);
	sort(v[1],vn[1]);
	long lo=0,hi=1l<<34;
	while(lo+1<hi){
		long z=lo+hi>>1;
		int c=vn[0]*vn[1];
		int j=vn[1]-1;
		rep(i,vn[0]){
			while(j>=0&&v[0][i]+v[1][j]>=z){
				--j;
			}
			c-=j+1;
		}
		if(c<k){
			hi=z;
		}else{
			lo=z;
		}
	}
	wt1(lo+o);
	_exit(0);
}
0