QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#487646 | #7743. Grand Finale | CSQ | WA | 141ms | 52404kb | C++14 | 3.2kb | 2024-07-23 04:28:50 | 2024-07-23 04:28:50 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int dp[2511][2511]; //is it possible to draw all cards 1 to i st j draw 1 cards used
int dp2[2511][2511]; //min draw 2 cards needed to win from i if you start from j draw 1 cards
int main()
{
owo
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
string s,t;
cin>>s>>t;
for(int i=0;i<=m;i++){
for(int j=0;j<=m;j++)dp[i][j] = 0;
}
dp[0][0] = 1;
int cnt1 = 0,cnt2 = 0;
for(char c:s){
cnt1 += c == 'Q';
cnt2 += c == 'B';
}
for(int i=0;i<m;i++){
for(int j=0;j<=i;j++){
if(!dp[i][j])continue;
int k = (i-j)/2; //draw 2 used
if(cnt1 - j > 0)dp[i+1][j+1] = 1;
if(cnt2 - k > 0 && i+2<=m)dp[min(m,i+2)][j] = 1;
}
cnt1 += t[i] == 'Q';
cnt2 += t[i] == 'B';
}
for(int i=0;i<m;i++){
for(int j=0;j<=m;j++)dp2[i][j] = 1e9;
}
for(int j=0;j<=m;j++)dp2[m][j] = 0;
for(int i=m-1;i>=0;i--){
for(int j=0;j<=m;j++){
int cb = t[i] == 'B';
int cq = t[i] == 'Q';
if(j)dp2[i][j] = min(dp2[i][j],max(0,dp2[i+1][j + cq-1] - cb));
dp2[i][j] = min(dp2[i][j],dp2[min(m,i+2)][j+cq] + 1 - cb);
}
}
// for(int i=0;i<=m;i++){
// for(int j=0;j<=m;j++)cout<<dp2[i][j]<<" ";
// }
cnt1 = cnt2 = 0;
for(char c:s){
cnt1 += c == 'Q';
cnt2 += c == 'B';
}
int ans = 1e9;
for(int i=0;i<=m;i++){
for(int j=0;j<=i;j++){
if(!dp[i][j])continue;
int k = (i-j)/2;
int hand = sz(s) + k;
// cout<<i<<" "<<j<<" "<<k<<'\n';
// cout<<dp2[i][min(m,cnt1-j)];
// cout<<'\n';
//cout<<cnt1<<" "<<cnt2<<'\n';
//cout<<i<<" "<<j<<" "<<k<<" "<<cnt1-j<<" "<<cnt2-k<<'\n';
if(cnt2 - k >= dp2[i][min(m,cnt1-j)]){
ans = min(ans,hand);
}
}
if(i<m){
cnt1 += t[i] == 'Q';
cnt2 += t[i] == 'B';
}
}
if(ans==1e9){
cout<<"IMPOSSIBLE"<<'\n';
}
else cout<<ans<<'\n';
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5616kb
input:
2 2 6 BG BQWBWW 4 6 GQBW WWWWQB
output:
3 IMPOSSIBLE
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 5700kb
input:
2 3 8 QBG BBBWBWWW 3 8 QBG BBBWBWWW
output:
3 3
result:
ok 2 lines
Test #3:
score: -100
Wrong Answer
time: 141ms
memory: 52404kb
input:
13 184 887 WBQBBWWBQBQBQBWWBBQQWWQQQBBBQWWWQWBBBBWWWQQBQQQWQBBQQWQQBBWWQWQQBWBQWWWWQWQQWQBWWQQWWQQBWWQWBBBWWQWBQBQWQQWWBQBQQBWQBQBWWBWQWQWBWBQWWQBQQQBWQQWQWWBQBWWQQBQWBQQBQQBQBBQBWBQQWWQBWBBQQBQG QWBQBQBWBQQWWWWQBBBQQQBBBWWWWQWQWWQQQBQBWQQQBWQWQBWWBQQQWQWBQBBQBWBBWBQWQBWWQQBWQQWWQWWQQWBQQWQWBBQBWBQQ...
output:
184 372 316 161 118 534 IMPOSSIBLE 631 183 276 33 160 642
result:
wrong answer 13th lines differ - expected: '643', found: '642'