# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
96294 | figter001 | Paint By Numbers (IOI16_paint) | C++14 | 2073 ms | 96916 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+50;
const int maxk = 110;
int n;
vector<int> c;
string s;
int dp[maxn][maxk];
bool can[maxn][2];
int calc(int idx,int at){
if(idx >= n)return (at == (int)c.size());
int &res = dp[idx][at];
if(res != -1)return res;
res = 0;
if(s[idx] == 'X'){
if(at == c.size()){
res = 0;
return res;
}
int to = idx + c[at] - 1;
if(to >= n){
res = 0;
return res;
}
for(int i=idx;i<=to;i++)if(s[i] == '_')return res = 0;
if(s[to + 1] == 'X')return res = 0;
res = calc(to+2,at+1);
if(res){
can[to+1][1] = 1;
for(int i=idx;i<=to;i++)can[i][0] = 1;
}
}
else if(s[idx] == '_'){
res = calc(idx+1,at);
}else{
res = calc(idx+1,at);
if(res)can[idx][1] = 1;
if(at != c.size()){
int to = idx + c[at] - 1;
if(to < n){
bool f = 1;
for(int i=idx;i<=to;i++)if(s[i] == '_')f = 0;
if(f){
if(s[to + 1] != 'X'){
res |= calc(to+2,at+1);
if(calc(to+2,at+1)){
can[to+1][1] = 1;
for(int i=idx;i<=to;i++)can[i][0] = 1;
}
}
}
}
}
}
return res;
}
string solve_puzzle(string S, vector<int> C){
memset(dp,-1,sizeof(dp));
n = S.size();
c = C;
s = S;
calc(0,0);
string ans;
for(int i=0;i<n;i++){
if(s[i] == '.'){
if(can[i][0] && can[i][1])ans += '?';
else if(can[i][1])ans += '_';
else ans += 'X';
}else ans += s[i];
}
return ans;
}
Compilation message (stderr)
# | 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... |