이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define INF 10000000000000000
#define MOD 1000000017
#define mid(l, u) ((l+u)/2)
#define rchild(i) (i*2 + 2)
#define lchild(i) (i*2 + 1)
using namespace std;
int n, k;
vector<int> cc;
string str;
int sum[200005];
int prevb[200005];
int dp[200005][105];
bool white[200005];
int black[200005];
int f(int i, int j){
if(j>=k && i>n){
return 1;
}
if(i>n){
return 0;
}
if(dp[i][j]!=-1){
return dp[i][j];
}
if(j>=k){
if(str[i]=='X') return dp[i][j] = 0;
int temp = f(i+1, j);
if(temp==1) white[i-1] = true;
return dp[i][j] = temp;
}
if(str[i-1]=='_'){
int temp = f(i+1, j);
if(temp>=1) white[i-1] = true;
return dp[i][j] = temp;
}
if((i+cc[j]-1)>n){
return dp[i][j] = 0;
}
int ans = 0;
if(((sum[i+cc[j]-1] - sum[i-1])==0) && ((i+cc[j]<=n)?(str[i+cc[j]-1]!='X'):true)) {
int temp = f(i+cc[j]+1, j+1);
if(temp>=1){
black[i-1]++;
black[i+cc[j]-1]--;
white[i+cc[j]-1] = true;
}
ans+=temp;
}
if(str[i-1]!='X'){
int temp = f(i+1, j);
if(temp>=1){
white[i-1] = true;
}
ans+=temp;
}
if(ans>=1) ans = 1;
return dp[i][j] = ans;
}
string solve_puzzle(string s, vector<int> c){
str = s;
cc = c;
k = c.size();
n = s.length();
string ans = s;
sum[0] = 0;
for(int i = 0;i<n;i++){
if(s[i]=='_'){
sum[i+1]=1;
}
else sum[i+1] = 0;
sum[i+1]+=sum[i];
}
for(int i = 0;i<=n;i++){
for(int j = 0;j<=k;j++){
dp[i][j] = -1;
}
}
int ind = 0;
for(int i = 1;i<=n;i++){
prevb[i] = ind;
if(s[i-1]=='X') ind = i;
}
for(int i = 0;i<=n;i++) white[i] = false;
for(int i = 0;i<=n;i++) black[i] = 0;
f(1, 0);
for(int i = 0;i<n;i++) ans[i] = '?';
for(int i = 1;i<n;i++) black[i]+=black[i-1];
for(int i = 0;i<n;i++){
if(black[i]==0) ans[i] = '_';
if(white[i]==false) ans[i] = 'X';
}
return ans;
}
/*signed main(){
string s;
int kk;
vector<int> c;
cin>>s>>kk;
for(int i = 0;i<kk;i++){
int temp;
cin>>temp;
c.push_back(temp);
}
cout<<solve_puzzle(s, c)<<endl;
}*/
# | 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... |