QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#439079 | #8768. Arrested Development | PetroTarnavskyi# | WA | 0ms | 4868kb | C++20 | 1.9kb | 2024-06-11 15:49:00 | 2024-06-11 15:49:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int M = 42;
const int M2 = 407;
const int K = 2547;
bitset<K> dp[M][M][M2];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
string s;
cin >> n >> k >> s;
dp[0][0][0].set(0);
FOR(i, 0, n)
{
FOR(N, 0, i + 1)
{
FOR(NA, 0, M2)
{
if (s[i] == '?' || s[i] == 'N')
dp[i + 1][N + 1][NA] |= dp[i][N][NA];
if ((s[i] == '?' || s[i] == 'A') && NA + N < M2)
dp[i + 1][N][NA + N] |= dp[i][N][NA];
if (s[i] == '?' || s[i] == 'C')
dp[i + 1][N][NA] |= dp[i][N][NA] << NA;
if (s[i] != 'N' && s[i] != 'A' && s[i] != 'C')
dp[i + 1][N][NA] |= dp[i][N][NA];
}
}
}
int N = -1, NA = -1;
FOR(j, 0, M)
FOR(l, 0, M2)
if (dp[n][j][l][k])
{
N = j;
NA = l;
break;
}
cerr << N << " " << NA << endl;
if (N == -1)
{
cout << "-1\n";
return 0;
}
string ans;
RFOR(i, n, 0)
{
if ((s[i] == '?' || s[i] == 'N') && N - 1 >= 0 && dp[i][N - 1][NA][k])
{
ans += 'N';
N--;
}
else if ((s[i] == '?' || s[i] == 'A') && NA - N >= 0 && dp[i][N][NA - N][k])
{
ans += 'A';
NA -= N;
}
else if ((s[i] == '?' || s[i] == 'C') && k - NA >= 0 && dp[i][N][NA][k - NA])
{
ans += 'C';
k -= NA;
}
else if (s[i] != 'N' && s[i] != 'A' && s[i] != 'C' && dp[i][N][NA][k])
{
ans += 'B';
}
else
{
assert(false);
}
}
assert(N == 0 && NA == 0 && k == 0);
reverse(ALL(ans));
cout << ans << "\n";
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 4868kb
input:
4 100 1 1 90 1 20 1 20
output:
-1
result:
wrong answer 1st lines differ - expected: '3', found: '-1'