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<bits/stdc++.h>
#include "paint.h"
using namespace std;
std::string solve_puzzle(std::string s, std::vector<int> c) {
vector<int> pref(c.size()+1), suf(c.size()+1);
vector<int> a(s.size());
int n=s.size();
int t=0;
for(int i = n-1; i>=0; i--){
if(s[i]!='_') t++;
else t = 0;
a[i] = t;
}
int l=0, pos=0;
pref[0]=-1;
while(pos<n&&l<c.size()){
if(a[pos]>=c[l]){
pref[l+1] = pos+c[l];
pos+=c[l]+1;
l++;
}
else{
pos++;
}
}
t = 0;
for(int i = 0; i<n; i++){
if(s[i]!='_') t++;
else t = 0;
a[i] = t;
}
suf[0] = n;
pos=n-1, l = 0;
while(pos>=0&&l<c.size()){
if(a[pos]>=c[c.size()-l-1]){
suf[l+1] = pos-c[c.size()-l-1];
pos-=c[c.size()-l-1]-1;
l++;
}
else{
pos++;
}
}
vector<int> vis(n), vis2(n);
t=0;
for(int i = n-1; i>=0; i--){
if(s[i]!='_') t++;
else t = 0;
a[i] = t;
}
for(int j=0; j<=c.size(); j++){
for(int l=max(0, pref[j]); l<=min(n-1, suf[c.size()-j]); l++){
vis[l]=1;
}
int ma=-1;
if(j!=c.size()){
for( int l=max(-1, pref[j])+1; l<min(n, suf[c.size()-j-1]); l++){
if(a[l]>=c[j]&&l+c[j]<=min(n, suf[c.size()-j-1])){
ma=l+c[j];
}
if(ma>=l){
vis2[l]=1;
}
}
}
}
string x;
for(int i=0; i<n; i++){
if(s[i]=='X') x+="X";
else if(s[i]=='_') x+="_";
else if(!vis[i]) x+='X';
else if(vis2[i])x+='?';
else x+='_';
}
t = 0;
return x;
return "";
}
/*
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
assert(1 == scanf("%s", buf));
std::string s = buf;
int c_len;
assert(1 == scanf("%d", &c_len));
std::vector<int> c(c_len);
for (int i = 0; i < c_len; i++) {
assert(1 == scanf("%d", &c[i]));
}
std::string ans = solve_puzzle(s, c);
// BEGIN SECRET
// puts("098d134608c94f7413faac591054ee35");
// END SECRET
// printf("%s\n", ans.data());
return 0;
}
*/
Compilation message (stderr)
paint.cpp: In function 'std::string solve_puzzle(std::string, std::vector<int>)':
paint.cpp:22:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | while(pos<n&&l<c.size()){
| ~^~~~~~~~~
paint.cpp:46:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | while(pos>=0&&l<c.size()){
| ~^~~~~~~~~
paint.cpp:65:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int j=0; j<=c.size(); j++){
| ~^~~~~~~~~~
paint.cpp:71:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | if(j!=c.size()){
| ~^~~~~~~~~~
# | 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... |