QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#262738 | #7743. Grand Finale | nameless_story# | WA | 133ms | 34776kb | C++20 | 1.6kb | 2023-11-23 22:37:29 | 2023-11-23 22:37:30 |
Judging History
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+3,inf*2));
fill(all(f[n+1]),0);
fill(all(f[n+2]),0);
for (i=n; i; i--) for (j=0; j<=n+m; 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+3,vector<char>(n+m+3,0));
g[0][0]=1;
for (i=0; i<=n+m; i++) for (j=0; j<=n+m; 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; k++) for (j=0; j<=n+m; j++)
{
i=(k-m)*2+j;
cmin(i,n);
int c2=sum[2][i]+cnt[2];
if (g[j][k-m]&&f[i+1][j]<=c2-(k-m))
{
cout<<k<<'\n';
k=n+m+2;
break;
}
}
// continue;
if (k==n+m+1) cout<<"IMPOSSIBLE\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3388kb
input:
2 2 6 BG BQWBWW 4 6 GQBW WWWWQB
output:
3 IMPOSSIBLE
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3448kb
input:
2 3 8 QBG BBBWBWWW 3 8 QBG BBBWBWWW
output:
3 3
result:
ok 2 lines
Test #3:
score: -100
Wrong Answer
time: 133ms
memory: 34776kb
input:
13 184 887 WBQBBWWBQBQBQBWWBBQQWWQQQBBBQWWWQWBBBBWWWQQBQQQWQBBQQWQQBBWWQWQQBWBQWWWWQWQQWQBWWQQWWQQBWWQWBBBWWQWBQBQWQQWWBQBQQBWQBQBWWBWQWQWBWBQWWQBQQQBWQQWQWWBQBWWQQBQWBQQBQQBQBBQBWBQQWWQBWBBQQBQG QWBQBQBWBQQWWWWQBBBQQQBBBWWWWQWQWWQQQBQBWQQQBWQWQBWWBQQQWQWBQBBQBWBBWBQWQBWWQQBWQQWWQWWQQWBQQWQWBBQBWBQQ...
output:
184 243 334 161 133 359 253 384 205 230 33 160 340
result:
wrong answer 2nd lines differ - expected: '372', found: '243'