QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#627418#7743. Grand FinaleRosmontispesWA 48ms107408kbC++202.9kb2024-10-10 15:50:502024-10-10 15:50:50

Judging History

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

  • [2024-10-10 15:50:50]
  • 评测
  • 测评结果:WA
  • 用时:48ms
  • 内存:107408kb
  • [2024-10-10 15:50:50]
  • 提交

answer

#include <bits/stdc++.h>  
using namespace std;  
using ll = long long;
const int N = 5000 + 20;
const int inf = 0x3f3f3f3f;
//f:共抽了i张牌,共打了j张后空翻,最少需要打多少张快斩才能抽完
int f[N][N],g[N][N];
int num[N][3];
int n,m;
int query(int i,int j){
    if(2 * j >= m - i)
        return 0;
    return f[i][j];
}
int idx(char c){
    if(c == 'W' || c == 'G')
        return 0;
    else if(c == 'Q')
        return 1;
    else
        return 2;
}
void solve() {
    cin>>n>>m;
    string S,T;
    cin>>S>>T;
    for(int i = 0;i <= n + m;i ++)
        for(int j = 0;j < 3;j ++)
            num[i][j] = 0;
    for(int i = 0;i < (int)S.size();i ++)
        num[0][idx(S[i])] ++;
    for(int i = 0;i < m;i ++){
        for(int j = 0;j < 3;j ++)
            num[i + 1][j] += num[i][j];
        num[i + 1][idx(T[i])] ++;
    }
    for(int i = 0;i <= n + m;i ++)
        for(int j = 0;j <= n + m;j ++)
            f[i][j] = inf,g[i][j] = 0;
    
    for(int i = m - 1;i >= 0;i --){
        for(int j = 0;2 * j < m - i;j ++){
            if(T[i] == 'W'){
                if(j > 0)
                    f[i][j] = min(query(i + 2,j - 1),f[i][j]);
                f[i][j] = min(query(i + 1,j) + 1,f[i][j]);
            } else if(T[i] == 'Q'){
                if(j > 0)
                    f[i][j] = min(max(query(i + 2,j - 1) - 1,0),f[i][j]);
                f[i][j] = min(max(query(i + 1,j),1) - 1,f[i][j]);
            } else {
                if(j > 0)
                    f[i][j] = min(query(i + 2,j),f[i][j]);
                f[i][j] = min(query(i + 1,j + 1) + 1,f[i][j]);
            }
        }
    }
    g[0][num[0][2]] = 1;
    for(int i = 0;i < m;i ++){
        for(int j = 0;j <= num[i][2];j ++){
            int qnum = num[i][1] - (i - (num[i][2] - j) * 2);
            if(qnum < 0)
                continue;
            if(qnum > 0){
                if(T[i] == 'B')
                    g[i + 1][j + 1] |= g[i][j];
                else
                    g[i + 1][j] |= g[i][j];
            }
            if(j > 0 && i + 2 <= m){
                int num = (T[i] == 'B'?1:0) + (T[i + 1] == 'B'?1:0);
                g[i + 2][j - 1 + num] |= g[i][j];
            }
        }
    }
    for(int i = n;i <= n + m;i ++){
        for(int j = 0;j <= m;j ++){
            int qnum = num[j][1] - (j - 2 * (i - n));
            int bnum = num[j][2] - (i - n);
            // if(bnum >= 0 && qnum >= 0)
                // cerr<<i<<" "<<j<<" "<<bnum<<" "<<g[j][bnum]<<" "<<query(j,bnum)<<"\n";
            if(bnum >= 0 && qnum >= 0 && g[j][bnum] && query(j,bnum) <= qnum){
                cout<<i<<"\n";
                return;
            }
        }
    }
    cout<<"IMPOSSIBLE\n";

}

int main() {  
    ios::sync_with_stdio(false);
    cin.tie(nullptr);  

    int T;
    cin>>T;
    while (T--) {
    	solve();
    }

}  
  

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

3
3

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 48ms
memory: 107408kb

input:

13
184 887
WBQBBWWBQBQBQBWWBBQQWWQQQBBBQWWWQWBBBBWWWQQBQQQWQBBQQWQQBBWWQWQQBWBQWWWWQWQQWQBWWQQWWQQBWWQWBBBWWQWBQBQWQQWWBQBQQBWQBQBWWBWQWQWBWBQWWQBQQQBWQQWQWWBQBWWQQBQWBQQBQQBQBBQBWBQQWWQBWBBQQBQG
QWBQBQBWBQQWWWWQBBBQQQBBBWWWWQWQWWQQQBQBWQQQBWQWQBWWBQQQWQWBQBBQBWBBWBQWQBWWQQBWQQWWQWWQQWBQQWQWBBQBWBQQ...

output:

184
66
164
161
118
117
28
125
134
89
33
160
73

result:

wrong answer 2nd lines differ - expected: '372', found: '66'