QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#262757#7743. Grand Finalenameless_story#WA 0ms3592kbC++201.6kb2023-11-23 23:01:302023-11-23 23:01:30

Judging History

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

  • [2023-11-23 23:01:30]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3592kb
  • [2023-11-23 23:01:30]
  • 提交

answer

#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
template<class T1,class T2> bool cmin(T1 &x,const T2 &y) { if (y<x) { x=y; return 1; }return 0; }
template<class T1,class T2> bool cmax(T1 &x,const T2 &y) { if (x<y) { x=y; return 1; }return 0; }
const string tt="WQBG";
const int inf=1e9;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int T; cin>>T;
	while (T--)
	{
		int n,m,i,j,k;
		cin>>m>>n;
		vector<int> a(n+1),cnt(4);
		vector sum(3,vector<int>(n+1));
		{
			string s;
			cin>>s;
			for (char c:s) ++cnt[tt.find(c)];
			cin>>s;
			for (i=0; i<n; i++) a[i+1]=tt.find(s[i]);
			for (i=1; i<=n; i++)
			{
				for (j=0; j<3; j++) sum[j][i]=sum[j][i-1];
				++sum[a[i]][i];
			}
		}
		vector f(n+3,vector<int>(n+m+4,inf));
		fill(all(f[n+1]),0);
		fill(all(f[n+2]),0);
		for (i=n; i; i--) for (j=0; j<=n+m+1; j++)
		{
			if (j) cmin(f[i][j],f[i+1][j-1+(a[i]==1)]);
			cmin(f[i][j],max(1,f[i+2][j+(a[i]==1)]+1-(a[i]==2)));
		}
		vector g(n+m+5,vector<char>(n+m+5,0));
		g[0][0]=1;
		for (i=0; i<=n+m+2; i++) for (j=0; j<=n+m+2; j++)
		{
			int x=min(n,i+j*2);
			int c1=sum[1][x]+cnt[1],c2=sum[2][x]+cnt[2];
			if (c1>=i&&c2>=j)
			{
				if (c1>i) g[i+1][j]|=g[i][j];
				if (c2>j) g[i][j+1]|=g[i][j];
			}
		}
		for (k=m; k<=n+m+1; k++) for (j=0; j<=n+m+1; j++)
		{
			i=(k-m)*2+j;
			cmin(i,n);
			int c1=sum[1][i]+cnt[1],c2=sum[2][i]+cnt[2];
			if (g[j][k-m]&&c1>=j&&f[i+1][c1-j]<=c2-(k-m))
			{
				cout<<k<<'\n';
				k=n+m+2;
				break;
			}
		}
		// continue;
		if (k==n+m+1) cout<<"IMPOSSIBLE\n";
	}
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3592kb

input:

2
2 6
BG
BQWBWW
4 6
GQBW
WWWWQB

output:

3

result:

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