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>
#define int long long
using namespace std;
string solve_puzzle(string s, vector<signed> c) {
int n = s.size(), k = c.size();
string ans = s;
vector<int> l(k),r(k);
//put all to the lefts
int p = 0;
for(int i = 0; i < k; i ++){
bool okay;
do{
okay = true; int mine = 0;
for(int j = p; j < p + c[i]; j ++){
if(s[j] == '_'){ okay = false; mine = j; break; }
}
if(okay){ r[i] = p + c[i]; p += c[i] + 1; }
else p = mine + 1;
}while(!okay);
}
//put all to the rights
p = n;
for(int i = k-1; i >= 0; i --){
bool okay;
do{
okay = true; int mine = 0;
for(int j = p-1; j >= p-c[i]; j --){
if(s[j] == '_'){ okay = false; mine = j; break; }
}
if(okay){ l[i] = p - c[i]; p -= c[i] + 1; }
else p = mine;
}while(!okay);
}
//apply x's
for(int i = 0; i < k; i ++){
for(int j = l[i]; j < r[i]; j ++) ans[j] = 'X';
}
//clean up?
bool vague = false; char prev = '_';
for(int i = 0; i < n; i ++){
if(prev == '_' && ans[i] == 'X'){ vague = false; }
else if(prev == '_' && ans[i] == '.'){vague = true; ans[i] = '?';}
else if(prev == 'X' && ans[i] == '.'){ans[i] = (vague ? '?' : '_');}
else if(prev == '?' && ans[i] == '.'){ ans[i] = '?';}
prev = ans[i];
}
return ans;
}
# | 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... |