QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#767705 | #8034. Ban or Pick, What's the Trick | MIS_T__ | WA | 1ms | 3588kb | C++23 | 2.2kb | 2024-11-20 21:48:34 | 2024-11-20 21:48:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
int N,K;
cin >> N >> K;
vector<vector<vector<vector<i64>>>> dp(2,vector<vector<vector<i64>>>(2,vector<vector<i64>>(N+1,vector<i64>(K+1))));
vector a(2,vector<i64>(N+1));
sort(a[0].begin(),a[0].end());
sort(a[1].begin(),a[1].end());
for ( int i = 0 ; i < 2 ; i++ ) {
for ( int j = 1 ; j <= N ; j++ ) {
cin >> a[i][j];
}
}
for ( int i = 0 ; i < 2 ; i++ ) {
for ( int j = 1 ; j <= N ; j++ ) {
for ( int k = 1 ; k <= K ; k++ ) {
dp[i][0][j][k] = ((j >= 2)?dp[i][0][j-2][k]:0)+a[i][j-1]-( (j-1-2*k >= 0) ? a[i][j-1-2*k]:0 );
dp[i][1][j][k] = ((j >= 2)?dp[i][1][j-2][k]:0)+a[i][j]-( (j-2*k >= 0) ? a[i][j-2*k]:0 );
}
}
}
map<array<int,5>,i64>mp;
map<array<int,5>,i64>vis;
auto dfs = [&](auto&dfs,int A,int B,int kA,int kB,int cur)->i64{
if ( B == 0 ) {
int t = cur==0;
return dp[0][t][A][kA];
}
if ( A == 0 ) {
int t = cur==1;
return -dp[1][t][B][kB];
}
if ( kB == 0 ) {
int t = cur==0;
return dp[0][t][A][kA];
}
if ( kA == 0 ) {
int t = cur==1;
return -dp[1][t][B][kB];
}
// return 0;
array<int,5>U = {A,B,kA,kB,cur};
if ( vis[U] ) {
return mp[U];
}
i64 res;
if ( cur == 0 ) {
res = -1e18;
if ( A >= 1 ) res = max(dfs(dfs,A-1,B,kA-1,kB,cur^1)+a[0][A],res);
if ( B >= 1 ) res = max(dfs(dfs,A,B-1,kA,kB,cur^1),res);
} else {
res = 1e18;
if ( B >= 1 ) res = min(dfs(dfs,A,B-1,kA,kB-1,cur^1)-a[1][B],res);
if ( A >= 1 ) res = min(dfs(dfs,A-1,B,kA,kB,cur^1),res);
}
mp[{A,B,kA,kB,cur}] = res;
vis[{A,B,kA,kB,cur}] = 1;
// cout << A << ' ' << B << ' ' << kA << ' ' << kB << ' ' << ' ' << cur << ' ' << res << '\n';
return res;
};
// cout << 1 << '\n';
cout << dfs(dfs,N,N,K,K,0) << '\n';
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3396kb
input:
2 1 3 6 2 4
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
4 1 1 3 5 7 2 4 6 8
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
4 2 4 6 7 9 2 5 8 10
output:
3
result:
ok single line: '3'
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 3588kb
input:
10 5 42 13 60 42 100 82 22 98 14 55 100 41 89 24 65 38 69 26 37 16
output:
106
result:
wrong answer 1st lines differ - expected: '41', found: '106'