QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#345197 | #7743. Grand Finale | ucup-team173 | WA | 1ms | 3900kb | C++20 | 3.6kb | 2024-03-06 15:38:13 | 2024-03-06 15:38:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define Mp make_pair
#define pb push_back
#define SZ(a) (int(a.size()))
typedef long long ll;
typedef double db;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
std::mt19937_64 gen(std::chrono::system_clock::now().time_since_epoch().count());
ll get(ll l, ll r) { std::uniform_int_distribution<ll> dist(l, r); return dist(gen); }
void solve() {
int n, m;
cin >> n >> m;
string hand, s;
cin >> hand >> s;
hand = ' ' + hand;
s = ' ' + s;
vi hcnt(3);
for(auto ch : hand) {
if(ch == 'Q') hcnt[1]++;
else if(ch == 'B') hcnt[2]++;
else if(ch == 'W') hcnt[0]++;
}
n--;
vi disk(m + 1);
vector sum(m + 1, vi(3));
for(int i = 1; i <= m; i++) {
if(s[i] == 'Q') disk[i] = 1;
else if(s[i] == 'B') disk[i] = 2;
else if(s[i] == 'W') disk[i] = 0;
sum[i] = sum[i - 1];
sum[i][disk[i]]++;
}
const int inf = 1e9;
vector f(m + 10, vi(n + m + 10, inf)), g(m + 10, vi(n + m + 10));
g[0][hcnt[2]] = 1;
for(int i = 0; i < m; i++) {
for(int j = 0; j <= n + m; j++) {
if(g[i][j] == 0) continue;
int c2all = hcnt[2] + sum[i][2] - j;
int c1use = i - c2all * 2;
int c1 = hcnt[1] + sum[i][1] - c1use;
if(c1) {
g[i + 1][j + (disk[i + 1] == 2)] = 1;
}
if(j && i + 2 < m) {
g[i + 2][j - 1 + (disk[i + 1] == 2) + (disk[i + 2] == 2)] = 1;
}
}
}
// for(int i = 0; i <= m; i++)
// for(int j = 0; j <= n + m; j++) {
// if(g[i][j]) {
// cout << i << ' ' << j << '\n';
// }
// }
// cout << '\n';
for(int j = 0; j <= n + m; j++) {
f[m][j] = f[m + 1][j] = 0;
}
for(int i = m - 1; i >= 0; i--) {
for(int j = 0; j <= n + m; j++) {
if(disk[i + 1] == 2) {
f[i][j] = min(f[i][j], f[i + 1][j + 1] + 1);
if(j) f[i][j] = min(f[i][j], f[i + 2][j]);
} else if(disk[i + 1] == 1) {
f[i][j] = min(f[i][j], max(f[i + 1][j], 1));
if(j) f[i][j] = min(f[i][j], max(f[i + 2][j - 1] - 1, 0));
} else {
f[i][j] = min(f[i][j], f[i + 1][j] + 1);
if(j) f[i][j] = min(f[i][j], f[i + 2][j] + 1);
}
// f[i][j] = min(
// max(f[i + 1][j] + 1 - (disk[i + 1] == 1), 1), // use [1]
// j ? f[i + 2][j - 1] - (disk[i + 1] == 1) : inf // use [2]
// );
// cout << i << ' ' << j << ' ' << f[i][j] << '\n';
}
}
for(int k = n; k <= n + m; k++) {
int fl = 0;
for(int t = 0; t < m; t++) {
int tot = n + t;
int c0 = hcnt[0] + sum[t][0];
int c2 = hcnt[2] + sum[t][2] - (k - n);
int c1 = hcnt[1] + sum[t][1] - t + 2 * (k - n);
if(c1 >= 0 && c2 >= 0 && g[t][c2] && f[t][c2] <= c1) {
cout << k << ' ' << t << ' ' << c0 << ' '
<< c1 << ' ' << c2 << ' ' << f[t][c2] << '\n';
fl = 1;
break;
}
}
if(fl) {
cout << k << '\n';
return;
}
}
cout << "IMPOSSIBLE\n";
}
signed main() {
atexit([](){cerr << "time: " << (db)clock()/CLOCKS_PER_SEC << "s\n";});
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while(t--) solve();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3900kb
input:
2 2 6 BG BQWBWW 4 6 GQBW WWWWQB
output:
3 4 1 1 1 1 3 IMPOSSIBLE
result:
wrong answer 1st lines differ - expected: '3', found: '3 4 1 1 1 1'