이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
//#include "paint.h"
using namespace std;
int n,k,res[200005],ones[200005],z[200005],val;
bool pre[200005][105],su[200005][105];
string s,ret;
vector<int>c;
int v(int id){
if(s[id]=='X') return 1;
if(s[id]=='_') return 0;
if(s[id]=='.') return -1;
}
string solve_puzzle(string ss, vector<int> c) { s=ss;
n=s.size();
k=c.size();
for(int i=1;i<=n;i++){
if(s[i-1]=='_') z[i]=1;
z[i]+=z[i-1];
}
for(int i=1;i<=n;i++){
val=v(i-1);
if(val==1) break;
pre[i][0]=1;
}
for(int i=n;i>0;i--){
val=v(i-1);
if(val==1) break;
su[i][0]=1;
}
pre[0][0]=1;
su[n+1][0]=1;
for(int i=1;i<=n;i++){//prefix
val=v(i-1);
//cout<<i<<" "<<val<<endl;
if(val!=0)//1 & -1
{
for(int j=1;j<=k;j++){//cout<<c[j-1]<<" ";
if(i-c[j-1]+1>=1)
if(((i==c[j-1] && j==1) || (pre[i-c[j-1]-1][j-1] && s[i-c[j-1]-1]!='X')) && (z[i]-z[i-c[j-1]]==0))pre[i][j]=1;
}
}
if(val<=0)//0 & -1
{
for(int j=1;j<=k;j++){
if(pre[i-1][j])pre[i][j]=1;
}
}
}
reverse(c.begin(),c.end());
for(int i=n;i>0;i--){//sufix
val=v(i-1);
//cout<<i<<" "<<val<<endl;
if(val!=0)//1 & -1
{
for(int j=1;j<=k;j++){//cout<<c[j-1]<<" ";
if(i+c[j-1]-1<=n)
if(((i+c[j-1]-1==n && j==1) || (su[i+c[j-1]+1][j-1] && s[i+c[j-1]-1]!='X')) && !(z[i+c[j-1]-1]-z[i-1]))su[i][j]=1;
}
}
if(val<=0)//0 & -1
{
for(int j=1;j<=k;j++){
if(su[i+1][j])su[i][j]=1;
}
}
}
for(int i=1;i<=n;i++){
if(s[i-1]=='X') continue;
for(int j=0;j<=k;j++){
//cout<<i<<" "<<j<<" "<<su[i][j]<<endl;
if(pre[i-1][j]&&su[i+1][k-j]) {res[i]=1;}
}
}
reverse(c.begin(),c.end());
// cout<<su[1+c[0]+1][0]<<endl;
for(int i=1;i<=k;i++){
for(int j=1;j+c[i-1]-1<=n;j++){
if((z[j+c[i-1]-1]-z[j-1])==0 &&
((pre[j-2][i-1] && s[j-2]!='X') || (j==1 && i==1)) &&
((su[j+c[i-1]+1][k-i] && s[j+c[i-1]-1]!='X') || ((j+c[i-1]-1)==n) && i==k))
{ // cout<<i<<" "<<j<<endl;
ones[j]++;ones[j+c[i-1]]--;}
}
}
for(int i=1;i<=n;i++){
ones[i]+=ones[i-1];
if(ones[i]>0)
res[i]+=2;
}
for(int i=1;i<=n;i++){
if(res[i]==1) ret+='_';
if(res[i]==2) ret+='X';
if(res[i]==3) ret+='?';
}
return ret;
}
/*/
main(){
int a;
cin>>s;
cin>>n;
for(int i=0;i<n;i++){
cin>>a;
c.push_back(a);
}
cout<<solve_puzzle(s,c);
}
/**/
컴파일 시 표준 에러 (stderr) 메시지
paint.cpp:125:1: warning: "/*" within comment [-Wcomment]
/**/
paint.cpp: In function 'std::__cxx11::string solve_puzzle(std::__cxx11::string, std::vector<int>)':
paint.cpp:90:82: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
((su[j+c[i-1]+1][k-i] && s[j+c[i-1]-1]!='X') || ((j+c[i-1]-1)==n) && i==k))
~~~~~~~~~~~~~~~~~~^~~~~~~
paint.cpp: In function 'int v(int)':
paint.cpp:15:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# | 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... |