結果

問題 No.2161 Black Market
ユーザー tailstails
提出日時 2022-12-13 22:04:26
言語 cLay
(20240104-1)
結果
AC  
実行時間 172 ms / 7,000 ms
コード長 1,044 bytes
コンパイル時間 6,752 ms
コンパイル使用メモリ 228,768 KB
実行使用メモリ 38,460 KB
最終ジャッジ日時 2024-04-25 05:52:28
合計ジャッジ時間 8,893 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,632 KB
testcase_01 AC 3 ms
5,632 KB
testcase_02 AC 3 ms
5,760 KB
testcase_03 AC 3 ms
5,504 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,632 KB
testcase_06 AC 3 ms
5,632 KB
testcase_07 AC 3 ms
5,888 KB
testcase_08 AC 3 ms
6,016 KB
testcase_09 AC 4 ms
6,016 KB
testcase_10 AC 3 ms
6,016 KB
testcase_11 AC 3 ms
5,888 KB
testcase_12 AC 3 ms
5,760 KB
testcase_13 AC 2 ms
5,632 KB
testcase_14 AC 3 ms
5,632 KB
testcase_15 AC 3 ms
5,888 KB
testcase_16 AC 3 ms
5,760 KB
testcase_17 AC 3 ms
5,504 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,632 KB
testcase_20 AC 155 ms
20,796 KB
testcase_21 AC 161 ms
20,668 KB
testcase_22 AC 123 ms
19,756 KB
testcase_23 AC 166 ms
19,740 KB
testcase_24 AC 172 ms
38,460 KB
testcase_25 AC 65 ms
24,968 KB
testcase_26 AC 158 ms
37,972 KB
testcase_27 AC 34 ms
18,156 KB
testcase_28 AC 36 ms
19,184 KB
testcase_29 AC 12 ms
9,600 KB
testcase_30 AC 9 ms
7,404 KB
testcase_31 AC 108 ms
29,016 KB
testcase_32 AC 35 ms
17,772 KB
testcase_33 AC 17 ms
9,188 KB
testcase_34 AC 8 ms
8,192 KB
testcase_35 AC 9 ms
8,704 KB
testcase_36 AC 14 ms
8,908 KB
testcase_37 AC 9 ms
7,424 KB
testcase_38 AC 64 ms
19,140 KB
testcase_39 AC 7 ms
6,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

ll@n,@k,@l,@p;
ll n1=n>>1,n2=n-n1;
vector<pair<ll,ll>>g1[18],g2[18];

// hanbun zen rekkyo
g1[0].push_back({0,0});
rep(i,n1){
	ll@a,@b;
	rrep(j,i+1){
		for(auto x:g1[j]){
			g1[j+1].push_back({x.first+b,x.second+a});
		}
	}
}
g2[0].push_back({0,0});
rep(i,n2){
	ll@a,@b;
	rrep(j,i+1){
		for(auto x:g2[j]){
			g2[j+1].push_back({x.first+b,x.second+a});
		}
	}
}

// zaatsu cost
ll za[1<<18],zn=0;
rep(i,n1+1){
	for(auto x:g1[i]){
		za[zn++]=l-x.second;
	}
}
rep(i,n2+1){
	for(auto x:g2[i]){
		za[zn++]=x.second;
	}
}
coordcomp(zn,za);
zn=0;
rep(i,n1+1){
	for(auto&x:g1[i]){
		x.second=za[zn++];
	}
}
rep(i,n2+1){
	for(auto&x:g2[i]){
		x.second=za[zn++];
	}
}

// kazoeru
ll z=0;
ll j=0;
vector<pair<ll,ll>>g;
rrep(i,n1+1){
	while(j<=n2&&i+j<=k){
		g.insert(g.end(),g2[j].begin(),g2[j].end());
		++j;
	}
	sort(g.begin(),g.end());
	sort(g1[i].begin(),g1[i].end());
	ll l=g.size()-1;
	fenwick<ll>f;
	f.malloc(1<<18,1);
	for(auto x:g1[i]){
		while(l>=0&&x.first+g[l].first>=p){
			f.add(g[l].second,1);
			--l;
		}
		z+=f.get(x.second);
	}
}
wt(z);
0