QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#290848 | #7743. Grand Finale | jeffqi | WA | 1ms | 3600kb | C++20 | 2.2kb | 2023-12-25 17:49:07 | 2023-12-25 17:49:07 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
#define eb emplace_back
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define cerr if (test) cerr
#define freopen if (test) freopen
#define ui unsigned int
#define ull unsigned ll
#define i128 __int128
using namespace std;
const int test = 0;
namespace qiqi {
constexpr int inf = 2e9,C = 26;
constexpr auto mp_init() {
array<int,C> res;
res['Q'-'A'] = 1;
res['B'-'A'] = 2;
return res;
}
const array<int,C> mp(mp_init());
void main() {
int n,m; string s,t;
cin >> n >> m >> s >> t;
vector f(m+1+1,vi(n+m+1,inf));
fill(all(f[m]),0);
fill(all(f[m+1]),0);
vector<array<int,2>> cnt(m+1);
for (int i = 0; i < n; i++) {
if (mp[s[i]-'A']) {
cnt[0][mp[s[i]]-'A'-1]++;
}
}
for (int i = 0; i < m; i++) {
cnt[i+1] = cnt[i];
if (mp[t[i]-'A']) {
cnt[i+1][mp[t[i]]-'A'-1]++;
}
}
for (int i = m-1; i >= 0; i--) {
array<int,2> c;
for (int j = 0; j < 2; j++) {
c[j] = cnt[i+1][j]-cnt[i][j];
}
for (int j = 0; j <= n+i; j++) {
f[i][j] = min(f[i][j],max(1,f[i+1][j+c[1]]+1-c[0]));
}
for (int j = 1; j <= n+i; j++) {
f[i][j] = min(f[i][j],max(0,f[i+2][j-1+c[1]]-c[0]));
}
}
vector g((m+1)/2+1,vi(m+1,0)); g[0][0] = 1;
for (int i = 0; i <= (m+1)/2; i++) {
for (int j = 0; j <= max(0,m-i*2); j++) {
if (g[i][j]) {
int k = min(m,i*2+j);
int x = cnt[k][1]-i,y = cnt[k][0]-j;
if (f[k][x] <= y) {
cout << n+i << '\n';
return;
}
if (x > 0) {
g[i+1][j] = 1;
}
if (y > 0) {
g[i][j+1] = 1;
}
}
}
}
auto fail = []() {
cout << "IMPOSSIBLE\n";
};
return fail();
}
}
int main() {
clock_t st = clock();
freopen("test.in","r",stdin);
freopen("test.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
cin >> T;
while (T--) {
qiqi::main();
}
cerr << (double)(clock()-st)/CLOCKS_PER_SEC;
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3600kb
input:
2 2 6 BG BQWBWW 4 6 GQBW WWWWQB
output:
IMPOSSIBLE IMPOSSIBLE
result:
wrong answer 1st lines differ - expected: '3', found: 'IMPOSSIBLE'