QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#487636#7743. Grand FinaleCSQWA 132ms96756kbC++143.3kb2024-07-23 04:06:192024-07-23 04:06:20

Judging History

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

  • [2024-07-23 04:06:20]
  • 评测
  • 测评结果:WA
  • 用时:132ms
  • 内存:96756kb
  • [2024-07-23 04:06:19]
  • 提交

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 main()
{
    owo
    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        VII dp(m+2),dp2(m+2);
        for(int i=0;i<=m+1;i++){
            dp[i].assign(m+2,0);
            dp2[i].assign(m+2,1e18);

        }
        string s,t;
        cin>>s>>t;
        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
                assert(cnt1 >= j);
                assert(cnt2 >= k);
                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 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],max(0LL,dp2[i+1][j-1]-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);
            }
        }
        // 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<=i;j++){
                if(!dp[i][j])continue;
                int k = (i-j)/2; 
                int hand = sz(s) + k;
                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: 0ms
memory: 3488kb

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: 3544kb

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

3
3

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 132ms
memory: 96756kb

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'