QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#262744 | #7743. Grand Finale | nameless_story# | WA | 148ms | 34892kb | C++20 | 1.6kb | 2023-11-23 22:46:36 | 2023-11-23 22:46:36 |
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+4,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+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+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 c1=sum[1][i]+cnt[1],c2=sum[2][i]+cnt[2];
if (g[j][k-m]&&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";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
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: 3780kb
input:
2 3 8 QBG BBBWBWWW 3 8 QBG BBBWBWWW
output:
3 3
result:
ok 2 lines
Test #3:
score: -100
Wrong Answer
time: 148ms
memory: 34892kb
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'