QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#347201#7743. Grand Finaleucup-team3160#WA 41ms54480kbC++147.2kb2024-03-09 12:13:212024-03-09 12:13:21

Judging History

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

  • [2024-03-09 12:13:21]
  • 评测
  • 测评结果:WA
  • 用时:41ms
  • 内存:54480kb
  • [2024-03-09 12:13:21]
  • 提交

answer

/*
  author:honglan0731
  Sexy_honglan0301 _ xiaoqing
 */
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cctype>
#include <queue>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <cmath>
#include <random>
#include <set>
#include <bitset>
#include <assert.h>
using namespace std;

//namespace Fread{const int SIZE=1<<20;char buf[SIZE],*S,*T;inline char getchar(){if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return'\n';}return*S++;}}using namespace Fread;namespace Fwrite{const int SIZE=1<<20;char buf[SIZE],*S=buf,*T=buf+SIZE;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==T)flush();}struct NTR{~NTR(){flush();}}ztr;}using namespace Fwrite;
//#define getchar Fread::getchar
//#define putchar Fwrite::putchar

namespace Fastio{struct Reader{template<typename T>Reader&operator>>(T&x){x=0;short f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();x*=f;return*this;}Reader&operator>>(double&x){x=0;double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(long double&x){x=0;long double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(__float128&x){x=0;__float128 t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(char&c){c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();return*this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}Reader&operator>>(string&str){str.clear();char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';struct Writer{const int Setprecision=6;typedef int mxdouble;template<typename T>Writer&operator<<(T x){if(x==0){putchar('0');return*this;}if(x<0)putchar('-'),x=-x;static short sta[40];short top=0;while(x>0)sta[++top]=x%10,x/=10;while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(long double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(long double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(__float128 x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(__float128)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(char c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(string str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}using namespace Fastio;
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl//;fflush(stdout)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ull unsigned long long
#define MOD 998244353
mt19937 rnd(time(0));
mt19937_64 rndl(time(0));
int n , m ;
char s1[2505] , s2[2505] ;
int s[2505][3] ;
int dp[5005][5005] ;
bool f[5005][5005] ;
const int INF = 1e9 + 5 ;
void gets( int a , int b , int &c , int &d ) // b:1 ge shu c:2 ge shu d:0 ge shu
{
	int x2 = ( a + b - s[a][1] ) / 2 ;
	c = s[a][2] - x2 , d = s[a][0] ;
}
void solve()
{
	scanf("%d%d" , &n , &m) ;
	scanf("%s%s" , s1 + 1 , s2 + 1) ;
	s[0][0] = s[0][1] = s[0][2] = 0 ;
	for ( int i = 1 ; i <= n ; i++ )
		if ( s1[i] == 'Q' ) s[0][1] ++ ;
		else if ( s1[i] == 'B' ) s[0][2] ++ ;
		else s[0][0] ++ ;
	for ( int i = 1 ; i <= m ; i++ )
	{
		for ( int j = 0 ; j < 3 ; j++ ) s[i][j] = s[i - 1][j] ;
		if ( s2[i] == 'Q' ) s[i][1] ++ ;
		else if ( s2[i] == 'B' ) s[i][2] ++ ;
		else s[i][0] ++ ;
	}
//	for ( int i = 0 ; i <= m ; i++ ) printf("%d %d %d\n" , s[i][0] , s[i][1] , s[i][2]) ;
	for ( int i = m - 1 ; i >= 0 ; i-- )
	{
		for ( int j = 0 ; j <= n + m ; j++ ) dp[i][j] = INF ;
		for ( int j = 1 ; j <= n + m ; j++ )
		{
			if ( s2[i + 1] == 'W' ) dp[i][j] = min( dp[i][j] , dp[i + 2][j - 1] ) ;
			else if ( s2[i + 1] == 'Q' ) dp[i][j] = min( dp[i][j] , max( dp[i + 2][j - 1] - 1 , 0 ) ) ;
			else if ( s2[i + 1] == 'B' ) dp[i][j] = min( dp[i][j] , dp[i + 2][j] ) ;
 		}
 		for ( int j = 0 ; j <= n + m ; j++ )
 		{
 			if ( s2[i + 1] == 'W' ) dp[i][j] = min( dp[i][j] , dp[i + 1][j] + 1 ) ;
 			else if ( s2[i + 1] == 'Q' ) dp[i][j] = min( dp[i][j] , max( dp[i + 1][j] , 1 ) ) ;
 			else if ( s2[i + 1] == 'B' ) dp[i][j] = min( dp[i][j] , dp[i + 1][j + 1] + 1 ) ;
		}
//		for ( int j = 0 ; j <= n + m ; j++ ) printf("dp[%d][%d] %d\n" , i , j , dp[i][j]) ;
	}
	for ( int i = 0 ; i <= m ; i++ )
		for ( int j = 0 ; j <= n + m ; j++ ) f[i][j] = 0 ;
	f[0][s[0][1]] = true ;
	int ans = INF ;
	for ( int i = 0 ; i <= m ; i++ )
	{
		for ( int j = 0 ; j <= n + m ; j++ )
		{
			if ( ! f[i][j] ) continue ;
			int k , l ;
			gets( i , j , k , l ) ;
			if ( j < 0 || k < 0 || l < 0 ) continue ;
			if ( dp[i][k] <= j )
			{
//				printf("nows:%d %d %d %d\n" , i , j , k , l) ;
				ans = min( ans , j + k + l ) ;
			}
			if ( i == m ) continue ;
			if ( j >= 1 )
			{
				int nxti = min( i + 1 , m ) , nxtj = j ;
				if ( s2[i + 1] == 'Q' ) nxtj++ ;
				f[nxti][nxtj] = true ;
			}
			else if ( k >= 1 )
			{
				int nxti = min( i + 2 , m ) , nxtj = j ;
				if ( s2[i + 1] == 'Q' ) nxtj++ ;
				if ( s2[i + 2] == 'Q' ) nxtj++ ;
				f[nxti][nxtj] = true ;
			}
		}
	}
	if ( ans == INF ) puts("IMPOSSIBLE") ;
	else printf("%d\n" , ans) ;
}
int main()
{
	int t ;
	scanf("%d" , &t) ;
	while ( t -- ) solve() ;
	return 0 ;
}

詳細信息

Test #1:

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

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

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

3
3

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 41ms
memory: 54480kb

input:

13
184 887
WBQBBWWBQBQBQBWWBBQQWWQQQBBBQWWWQWBBBBWWWQQBQQQWQBBQQWQQBBWWQWQQBWBQWWWWQWQQWQBWWQQWWQQBWWQWBBBWWQWBQBQWQQWWBQBQQBWQBQBWWBWQWQWBWBQWWQBQQQBWQQWQWWBQBWWQQBQWBQQBQQBQBBQBWBQQWWQBWBBQQBQG
QWBQBQBWBQQWWWWQBBBQQQBBBWWWWQWQWWQQQBQBWQQQBWQWQBWWBQQQWQWBQBBQBWBBWBQWQBWWQQBWQQWWQWWQQWBQQWQWBBQBWBQQ...

output:

184
IMPOSSIBLE
316
IMPOSSIBLE
IMPOSSIBLE
IMPOSSIBLE
IMPOSSIBLE
IMPOSSIBLE
IMPOSSIBLE
IMPOSSIBLE
IMPOSSIBLE
IMPOSSIBLE
IMPOSSIBLE

result:

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