QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#290856#7743. Grand FinalejeffqiRE 0ms0kbC++202.1kb2023-12-25 17:53:332023-12-25 17:53:34

Judging History

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

  • [2023-12-25 17:53:34]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-12-25 17:53:33]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
#define eb emplace_back
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define cerr if (test) cerr
#define freopen if (test) freopen
#define ui unsigned int
#define ull unsigned ll
#define i128 __int128
using namespace std;

const int test = 0;

namespace qiqi {
	constexpr int inf = 2e9,C = 26;
	const map<char,int> mp{{'Q',0},{'B',1},{'G',-1},{'W',-1}};
	void main() {
		int n,m; string s,t;
		cin >> n >> m >> s >> t;
		vector f(m+1+1,vi(n+m+1,inf));
		fill(all(f[m]),0);
		fill(all(f[m+1]),0);
		vector<array<int,2>> cnt(m+1);
		for (int i = 0; i < n; i++) {
			if (mp.at(s[i])) {
				cnt[0][mp.at(s[i])-1]++;
			}
		}
		for (int i = 0; i < m; i++) {
			cnt[i+1] = cnt[i];
			if (mp.at(t[i])) {
				cnt[i+1][mp.at(t[i])-1]++;
			}
		}
		for (int i = m-1; i >= 0; i--) {
			array<int,2> c;
			for (int j = 0; j < 2; j++) {
				c[j] = cnt[i+1][j]-cnt[i][j];
			}
			for (int j = 0; j <= n+i; j++) {
				f[i][j] = min(f[i][j],max(1,f[i+1][j+c[1]]+1-c[0]));
			}
			for (int j = 1; j <= n+i; j++) {
				f[i][j] = min(f[i][j],max(0,f[i+2][j-1+c[1]]-c[0]));
			}
		}
		vector g((m+1)/2+1,vi(m+1,0)); g[0][0] = 1;
		for (int i = 0; i <= (m+1)/2; i++) {
			for (int j = 0; j <= max(0,m-i*2); j++) {
				if (g[i][j]) {
					int k = min(m,i*2+j);
					int x = cnt[k][1]-i,y = cnt[k][0]-j;
					if (f[k][x] <= y) {
						cout << n+i << '\n';
						return;
					}
					if (x > 0) {
						g[i+1][j] = 1;
					}
					if (y > 0) {
						g[i][j+1] = 1;
					}
				}
			}
		}
		auto fail = []() {
			cout << "IMPOSSIBLE\n";
		};

		return fail();
	}
}

int main() {
	clock_t st = clock();
	freopen("test.in","r",stdin);
	freopen("test.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int T = 1;
	cin >> T;
	while (T--) {
		qiqi::main();
	}

	cerr << (double)(clock()-st)/CLOCKS_PER_SEC;
	return 0;
}

详细

Test #1:

score: 0
Runtime Error

input:

2
2 6
BG
BQWBWW
4 6
GQBW
WWWWQB

output:


result: