QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#262759#7743. Grand Finalenameless_storyWA 155ms34772kbC++201.6kb2023-11-23 23:01:592023-11-23 23:02:00

Judging History

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

  • [2023-11-23 23:02:00]
  • 评测
  • 测评结果:WA
  • 用时:155ms
  • 内存:34772kb
  • [2023-11-23 23:01:59]
  • 提交

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+2) cout<<"IMPOSSIBLE\n";
	}
}

详细

Test #1:

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

input:

2
2 6
BG
BQWBWW
4 6
GQBW
WWWWQB

output:

3
IMPOSSIBLE

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 3368kb

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

3
3

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 155ms
memory: 34772kb

input:

13
184 887
WBQBBWWBQBQBQBWWBBQQWWQQQBBBQWWWQWBBBBWWWQQBQQQWQBBQQWQQBBWWQWQQBWBQWWWWQWQQWQBWWQQWWQQBWWQWBBBWWQWBQBQWQQWWBQBQQBWQBQBWWBWQWQWBWBQWWQBQQQBWQQWQWWBQBWWQQBQWBQQBQQBQBBQBWBQQWWQBWBBQQBQG
QWBQBQBWBQQWWWWQBBBQQQBBBWWWWQWQWWQQQBQBWQQQBWQWQBWWBQQQWQWBQBBQBWBBWBQWQBWWQQBWQQWWQWWQQWBQQWQWBBQBWBQQ...

output:

244
532
688
161
231
763
IMPOSSIBLE
740
377
437
33
160
755

result:

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