QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#487391#7743. Grand FinaleCSQWA 120ms52208kbC++143.7kb2024-07-22 21:01:012024-07-22 21:01:04

Judging History

你现在查看的是最新测评结果

  • [2024-07-22 21:01:04]
  • 评测
  • 测评结果:WA
  • 用时:120ms
  • 内存:52208kb
  • [2024-07-22 21:01:01]
  • 提交

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+1;i++){
            for(int j=0;j<=m+1;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;
               // assert((i-j)%2 == 0);
                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[i+2][j] = 1;
            }
            cnt1 += t[i] == 'Q';
            cnt2 += t[i] == 'B';
        }
        // for(int i=0;i<=m;i++){
        //     for(int j=0;j<=i;j++){
        //         if(dp[i][j])cout<<i<<" "<<j<<'\n';
        //     }
        // }

        for(int i=0;i<=m+1;i++){
            for(int j=0;j<=m+1;j++)dp2[i][j] = 1e9;
        }
        for(int j=0;j<=m+1;j++)dp2[m][j] = dp2[m+1][j] = 0;
        for(int i=m-1;i>=0;i--){
            for(int j=0;j<=m;j++){
                if(j){
                    if(t[i] == 'W')dp2[i][j] = min(dp2[i][j],dp2[i+1][j-1]);
                    if(t[i] == 'Q')dp2[i][j] = min(dp2[i][j],dp2[i+1][j]);
                    if(t[i] == 'B')dp2[i][j] = min(dp2[i][j],dp2[i+1][j-1]);
                }
                if(t[i] == 'B')dp2[i][j] = min(dp2[i][j],dp2[i+2][j]);
                if(t[i] == 'W')dp2[i][j] = min(dp2[i][j],dp2[i+2][j] + 1);
                if(t[i] == 'Q')dp2[i][j] = min(dp2[i][j],dp2[i+2][j+1] + 1);
                dp2[i][j] = max(dp2[i][j],0);
            }
        }
        // for(int i=0;i<m;i++){
        //     for(int j=0;j<=m-i;j++){
        //         if(dp2[i][j] > m)cout<<"INF ";
        //         else cout<<dp2[i][j]<<" ";
        //     }
        //     cout<<'\n';
        // }
        ///
        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<=m;j++){
                if(!dp[i][j])continue;
                int k = (i-j)/2; 
                int hand = sz(s) + i - j - k;
                //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';
    }
    
    


}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5640kb

input:

2
2 6
BG
BQWBWW
4 6
GQBW
WWWWQB

output:

3
IMPOSSIBLE

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 5712kb

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

3
3

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 120ms
memory: 52208kb

input:

13
184 887
WBQBBWWBQBQBQBWWBBQQWWQQQBBBQWWWQWBBBBWWWQQBQQQWQBBQQWQQBBWWQWQQBWBQWWWWQWQQWQBWWQQWWQQBWWQWBBBWWQWBQBQWQQWWBQBQQBWQBQBWWBWQWQWBWBQWWQBQQQBWQQWQWWBQBWWQQBQWBQQBQQBQBBQBWBQQWWQBWBBQQBQG
QWBQBQBWBQQWWWWQBBBQQQBBBWWWWQWQWWQQQBQBWQQQBWQWQBWWBQQQWQWBQBBQBWBBWBQWQBWWQQBWQQWWQWWQQWBQQWQWBBQBWBQQ...

output:

239
530
687
161
230
762
IMPOSSIBLE
737
376
436
33
160
755

result:

wrong answer 1st lines differ - expected: '184', found: '239'