QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#343935#7743. Grand Finaleucup-team992#WA 169ms101788kbC++202.4kb2024-03-03 10:01:042024-03-03 10:01:05

Judging History

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

  • [2024-03-03 10:01:05]
  • 评测
  • 测评结果:WA
  • 用时:169ms
  • 内存:101788kb
  • [2024-03-03 10:01:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
ll INF=1000000000;
int main() {
	vector<vector<bool>> DP0(2501, vector<bool>(2501, false));
	vector<vector<ll>> DP1(2501, vector<ll>(5001, -1));
	vector<ll> BPS(2501,0);
	vector<ll> QPS(2501,0);
	ll T; cin >> T;
	for(int t = 0; t < T; t++) {
		ll N, M; cin >> N >> M;
		string H,P;
		cin >> H;
		cin >> P;
		ll B0=0, Q0=0;
		for(int i = 0; i < N; i++) {
			if(H[i] == 'B') B0++;
			else if(H[i] == 'Q') Q0++;
		}

		BPS.assign(M+1,0);
		QPS.assign(M+1,0);
		for(int j = 0; j < M; j++) {
			if(P[j] == 'B') BPS[j+1]++;
			else if(P[j] == 'Q') QPS[j+1]++;
			BPS[j+1] += BPS[j]; QPS[j+1] += QPS[j];
		}
		
		ll R = INF;

		for(int i = 0; i <= M; i++) DP0[i].assign(M+1, false);
		for(int i = 0; i <= M; i++) DP1[i].assign(M+N+1,INF);

		DP1[M].assign(M+N+1,0);
		for(int i = M-1; i >= 0; i--) {
			for(int b = 0; b <= N+M; b++) {
				// we are at full hand-size.
				// play a Q from here...
				{
					ll bthen = b;
					if(P[i+1] == 'B') bthen--;
					ll cost = 0;
					if(P[i+1] == 'Q') cost = 1;
					if(bthen >= 0) {
						DP1[i][b] = min(DP1[i][b], 1 + max(DP1[i+1][bthen]-cost,0LL));
					}
				}


				// played a B to get here.
				if(b > 0) {
					if(i+2 > M) {
						DP1[i][b] = 0;
					} else {
						ll bthen = b-1;
						if(P[i+1] == 'B') bthen++;
						ll cost = 0;
						if(P[i+1] == 'Q') cost=1;
						if(bthen >= 0) {
							DP1[i][b] = min(DP1[i][b], max(DP1[i+2][bthen]-cost,0LL));
						}
					}
				}

				//cout << i << " " << b << " " << DP1[i][b] << endl;
			}
		}


		DP0[0][0] = true;
		for(int i = 1; i <= M; i++) {
			for(int b = 0; (2*b <= i); b++) {
				// (i-1,b) -> (i, b)
				{
					ll qthen = QPS[i-1] + Q0;
					ll qspent = i-1 - 2*b;
					if((qthen - qspent > 0) && DP0[i-1][b]) DP0[i][b] = true;
				}

				// (i-2, b-1) -> (i,b)
				if(i-2>=0 && b-1>=0) {
					ll bthen = BPS[i-2] + B0;
					ll bspent = b-1;
					if((bthen - bspent)>0 && DP0[i-2][b-1]) DP0[i][b] = true;
				}

				


				
			}
		}

		for(int i = 0; i <= M; i++) for(int b = 0; b <= M; b++) {
			ll qnow = QPS[i] + Q0;
			qnow -= i - 2*b;
			ll bnow = BPS[i]+B0-b;
			if(DP0[i][b] && qnow >= DP1[i][bnow]) R = min(R, N+b);
		}


		if(R == INF) {
			cout << "IMPOSSIBLE\n"; continue;
		}

		cout << R << endl;
	}
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 101596kb

input:

2
2 6
BG
BQWBWW
4 6
GQBW
WWWWQB

output:

3
IMPOSSIBLE

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 3ms
memory: 101760kb

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

3
3

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 169ms
memory: 101788kb

input:

13
184 887
WBQBBWWBQBQBQBWWBBQQWWQQQBBBQWWWQWBBBBWWWQQBQQQWQBBQQWQQBBWWQWQQBWBQWWWWQWQQWQBWWQQWWQQBWWQWBBBWWQWBQBQWQQWWBQBQQBWQBQBWWBWQWQWBWBQWWQBQQQBWQQWQWWBQBWWQQBQWBQQBQQBQBBQBWBQQWWQBWBBQQBQG
QWBQBQBWBQQWWWWQBBBQQQBBBWWWWQWQWWQQQBQBWQQQBWQWQBWWBQQQWQWBQBBQBWBBWBQWQBWWQQBWQQWWQWWQQWBQQWQWBBQBWBQQ...

output:

243
532
688
161
231
764
IMPOSSIBLE
739
377
438
33
160
756

result:

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