이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "paint.h"
using namespace std;
typedef long long ll;
string solve_puzzle(string s,vector<int> c)
{
int n=s.size();
int k=c.size();
c.insert(c.begin(),0);
s="$"+s;
vector<int> wsum(n+1,0);
for(int i=1;i<=n;i++) wsum[i]=wsum[i-1]+(s[i]=='_');
auto ws=[&](int l,int r)->int{return (wsum[r]-wsum[l-1]);};
vector one(n+1,vector(k+1,vector(2,bool(0))));
one[0][0][1]=1;
for(int i=1;i<=n;i++)
{
//extend
for(int j=0;j<=k;j++) one[i][j][1]=((one[i-1][j][0]||one[i-1][j][1])&&(s[i]!='X'));
//new block
for(int j=1;j<=k;j++) if(i-c[j]>=0) one[i][j][0]=(one[i-c[j]][j-1][1]&&ws(i-c[j]+1,i)==0);
}
vector two(n+2,vector(k+2,vector(2,bool(0))));
two[n+1][k+1][1]=1;
for(int i=n;i>=1;i--)
{
//extend
for(int j=1;j<=k+1;j++) two[i][j][1]=((two[i+1][j][0]||two[i+1][j][1])&&(s[i]!='X'));
//new block
for(int j=1;j<=k;j++) if(i+c[j]<=n+1) two[i][j][0]=(two[i+c[j]][j+1][1]&&ws(i,i+c[j]-1)==0);
}
vector<int> d(n+2,0);
vector<bool> white(n+1,0);
for(int i=1;i<=n;i++)
{
//white
for(int j=0;j<=k;j++) if(one[i][j][1]&&two[i][j+1][1]) white[i]=1;
//black
for(int j=1;j<=k;j++)
{
if(one[i][j][0]&&two[i+1][j+1][1])
{
d[i-c[j]+1]++;
d[i+1]--;
}
}
}
int black=0;
string res(n,'?');
for(int i=1;i<=n;i++)
{
black+=d[i];
if(white[i]&&black) res[i-1]='?';
else if(white[i]) res[i-1]='_';
else if(black) res[i-1]='X';
}
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |