QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#264712#7743. Grand Finaleucup-team266#WA 86ms100700kbC++202.1kb2023-11-25 14:59:142023-11-25 14:59:15

Judging History

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

  • [2023-11-25 14:59:15]
  • 评测
  • 测评结果:WA
  • 用时:86ms
  • 内存:100700kb
  • [2023-11-25 14:59:14]
  • 提交

answer

/*
Things to notice:
1. do not calculate useless values
2. do not use similar names
 
Things to check:
1. submit the correct file
2. time (it is log^2 or log)
3. memory
4. prove your naive thoughts 
5. long long
6. corner case like n=0,1,inf or n=m
7. check if there is a mistake in the ds or other tools you use
8. fileio in some oi-contest

9. module on time 
10. the number of a same divisor in a math problem
11. multi-information and queries for dp and ds problems
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
const int mod=998244353;
const int inf=0x3f3f3f3f;
int dp[2505][5005],g[2505][5005];
char S[5005];
int n,m,s0[5005],s1[5005],s2[5005],w0,w1,w2;
bool chk(int pos,int c0,int c1,int c2)
{
	return c2>=g[pos+1][c1];
}
void solve()
{
	cin>>n>>m;
	w0=w1=w2=0;
	for(int i=1;i<=n;i++)
	{
		char ch;
		cin>>ch;
		if(ch=='W'||ch=='G') w0++;
		if(ch=='Q') w1++;
		if(ch=='B') w2++;
	}
	for(int i=0;i<=m+2;i++) for(int j=0;j<=n+m+2;j++) dp[i][j]=0,g[i][j]=(i>=m+1?0:inf);
	
	dp[0][w1]=1;
	for(int i=1;i<=m;i++) 
	{
		cin>>S[i];
		s0[i]=s0[i-1]+(S[i]=='W');
		s1[i]=s1[i-1]+(S[i]=='Q');
		s2[i]=s2[i-1]+(S[i]=='B');
	}
	for(int i=m;i>=1;i--) for(int c1=0;c1<=n+m;c1++)
	{
		// play 1
		if(c1) g[i][c1]=min(g[i][c1],g[i+1][c1-1+(S[i]=='Q')]);
		// play 2
		int cc1=c1;
		cc1+=(S[i]=='Q');
		g[i][c1]=min(g[i][c1],max(1,1+g[i+2][cc1]-(S[i]=='B')));
	}
	int ans=inf;
	for(int i=0;i<=m;i++) for(int c1=0;c1<=n+m;c1++) if(dp[i][c1])
	{
		int c0=w0+s0[i];
		int d1=w1+s1[i]-c1;
		int d2=(i-d1)/2;
		int c2=w2+s2[i]-d2;
//		cout<<i<<" "<<c0<<" "<<c1<<" "<<c2<<"\n";
		if(chk(i,c0,c1,c2)) ans=min(ans,c0+c1+c2);
		if(i+1<=m)
		{
			// play 1
			if(c1) dp[i+1][c1-1+(S[i+1]=='Q')]=1;
			// play 2
			if(c2)
			{
				int cc1=c1;
				if(S[i+1]=='Q') cc1++;
				if(i+2<=m&&S[i+2]=='Q') cc1++;
				dp[min(i+2,m)][cc1]=1;
			}
		}
	}
	if(ans>10000) cout<<"IMPOSSIBLE\n";
	else cout<<ans<<"\n";
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int _=1;
	cin>>_;
	while(_--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

3
3

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 86ms
memory: 100700kb

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'