結果

問題 No.1597 Matrix Sort
ユーザー tailstails
提出日時 2021-07-11 03:22:11
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 36 ms / 1,500 ms
コード長 1,335 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 31,324 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 20:03:52
合計ジャッジ時間 2,440 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

char*mmap();
#define rd(v) long v=0;{int _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 rep(v,e) for(long v=0;v<e;++v)

void radix_sort_aux(unsigned*a,unsigned*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]<<24;
	}
}

void radix_sort(unsigned*a,int n){
	static unsigned b[100000];
	radix_sort_aux(a,b,n);
	radix_sort_aux(b,a,n);
	radix_sort_aux(a,b,n);
	radix_sort_aux(b,a,n);
}

int a[100000],b[100000];
long n;

long count(int th){
	long r=0;
	long i=0,j=n-1;
	while(1){
		if(a[i]+b[j]<=th){
			r+=j+1;
			if(++i==n){
				break;
			}
		}else{
			if(--j<0){
				break;
			}
		}
	}
	return r;
}

main(){
	char*rp=mmap(0l,1l<<25,1,2,0,0ll);
	{ rd(ln); n=ln; }
	rd(k);
	rd(p);
	rep(i,n){
		rd(ai);
		a[i]=ai;
	}
	radix_sort(a,n);
	rep(i,n){
		rd(bi);
		b[i]=bi;
	}
	radix_sort(b,n);
	long off=-count(p-1);
	long rl=-1,rh=p-1;
	while(rl<rh-1){
		long rm=rl+rh>>1;
		long c=off+count(rm)+count(rm+p);
		if(c<k){
			rl=rm;
		}else{
			rh=rm;
		}
	}
	char wbuf[64],*wp=wbuf+sizeof wbuf;
	wt(rh);
	write(1,wp,wbuf+sizeof wbuf-wp);
	_exit(0);
}
0