QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#471129#8034. Ban or Pick, What's the TricksmlWA 453ms357500kbC++171.1kb2024-07-10 18:24:452024-07-10 18:24:45

Judging History

This is the latest submission verdict.

  • [2024-07-10 18:24:45]
  • Judged
  • Verdict: WA
  • Time: 453ms
  • Memory: 357500kb
  • [2024-07-10 18:24:45]
  • Submitted

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+10;
int a[N],b[N],n,k;
int dp[N][21][21];
bool cmp(int x,int y){
	return x>y;
}
int dfs(int round,int s_a,int s_b){
	if(round==2*n) return 0;
	if(dp[round][s_a][s_b]!=-1) return dp[round][s_a][s_b];
	int nowa=round/2-s_b+s_a;
	int nowb=(round+1)/2-s_a+s_b;
	int ans=-1e18;
	if(round%2==0){
		if(s_a<k&&nowa<n) ans=max(ans,dfs(round+1,s_a+1,s_b)+a[nowa+1]);
		ans=max(ans,dfs(round+1,s_a,s_b));
		return dp[round][s_a][s_b]=ans;
	}
	else{
		ans=1e18;
		if(s_b<k&&nowb<n) ans=min(ans,dfs(round+1,s_a,s_b+1)-b[nowb+1]);
		ans=min(ans,dfs(round+1,s_a,s_b));
		return dp[round][s_a][s_b]=ans;
	}
}
void solve()
{
   memset(dp,-1,sizeof(dp));
   cin>>n>>k;
   for(int i=1;i<=n;i++) cin>>a[i];
   for(int i=1;i<=n;i++) cin>>b[i];
   sort(a+1,a+1+n,cmp);
//   for(int i=1;i<=n;i++) cout<<a[i]<<' ';
//   cout<<'\n';
   sort(b+1,b+1+n,cmp);
   dfs(0,0,0);
   cout<<dp[0][0][0]<<'\n';
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--) solve();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 7ms
memory: 348464kb

input:

2 1
3 6
2 4

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 12ms
memory: 349488kb

input:

4 1
1 3 5 7
2 4 6 8

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 11ms
memory: 349496kb

input:

4 2
4 6 7 9
2 5 8 10

output:

3

result:

ok single line: '3'

Test #4:

score: 0
Accepted
time: 27ms
memory: 348820kb

input:

10 5
42 13 60 42 100 82 22 98 14 55
100 41 89 24 65 38 69 26 37 16

output:

41

result:

ok single line: '41'

Test #5:

score: 0
Accepted
time: 0ms
memory: 348592kb

input:

9 10
4 32 566 885 439 479 332 95 432
409 140 704 26 558 781 457 356 404

output:

58

result:

ok single line: '58'

Test #6:

score: 0
Accepted
time: 12ms
memory: 348752kb

input:

20 8
249 888 548 338 840 890 519 416 852 817 28 694 271 947 239 11 654 914 765 939
483 148 403 552 250 635 287 644 364 822 621 151 31 422 683 959 867 266 837 395

output:

1201

result:

ok single line: '1201'

Test #7:

score: 0
Accepted
time: 3ms
memory: 348284kb

input:

100 10
9813 7151 1299 6277 9002 7359 770 1582 3909 9113 1937 3436 846 9841 3378 5437 9443 9148 6862 6832 1910 1365 1328 26 7245 9468 6087 5828 8993 3378 6200 7242 6495 6783 7275 9837 5162 2140 3721 1586 7559 3721 9268 7186 1615 6648 5631 5752 3712 7856 7938 5414 9197 5259 3319 3616 3257 5880 2448 74...

output:

2174

result:

ok single line: '2174'

Test #8:

score: 0
Accepted
time: 123ms
memory: 355064kb

input:

40000 5
19274618 29347041 40087005 4241769 41812959 94623872 30100813 76644033 64979494 96963240 48832843 15280489 52008818 47041532 58608992 73517436 15625815 32168369 68934604 89208811 79580765 42310673 69912065 59918072 29961600 96203768 8736038 83397821 69327027 17923674 3664021 44005027 7651388...

output:

8194

result:

ok single line: '8194'

Test #9:

score: -100
Wrong Answer
time: 453ms
memory: 357500kb

input:

100000 10
85360465 81541239 77118024 87341741 99983425 10619868 1784917 20823381 74104953 35366414 80917288 72494315 44512062 20610367 84530471 73577105 48782904 9308066 74657628 58835630 19344370 85521394 91509750 31058798 76011614 78384876 52633286 93465152 62148686 46231760 69339331 74105686 4770...

output:

99728926

result:

wrong answer 1st lines differ - expected: '-46511', found: '99728926'