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;
typedef pair <ll, ll> pii;
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) (int)(v).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
string solve_puzzle(string s, vector<int> c) {
string res = "";
string a = "", b = "";
int pos = 0, i, clues = sz(c), j, n = sz(s);
vector <pii> borders(clues);
for(i = 0; i < n; i++){
a += '.';
b += '.';
res += '?';
}
for(i = 0; i < clues; i++){
int flag = -1;
while(pos < n && s[pos] == '_') pos++;
for(j = pos; j < pos+c[i]; j++){
if(s[j] == '_') flag = j;
}
if(flag == -1){
for(j = pos; j < pos+c[i]; j++){
a[j] = 'X';
}
borders[i].first = pos;
pos += c[i]+1;
}
else{
i--;
pos = flag+1;
}
}
pos = n-1;
for(i = clues-1; i >= 0; i--){
int flag = -1;
while(pos >= 0 && s[pos] == '_') pos--;
for(j = pos; j > pos-c[i]; j--){
if(s[j] == '_') flag = j;
}
if(flag == -1){
for(j = pos; j > pos-c[i]; j--){
b[j] = 'X';
}
borders[i].second = pos-c[i]+1;
pos -= (c[i]+1);
}
else{
i++;
pos = flag-1;
}
}
for(i = 0; i < n; i++){
if(s[i] == '_'){
res[i] = '_';
}
}
for(i = 0; i < clues; i++){
int l = borders[i].first, r = borders[i].second;
for(j = r; j < l+c[i]; j++){
res[j] = 'X';
}
borders[i].first = r;
borders[i].second = l+c[i];
}
for(i = 0; i < clues-1; i++){
int l1 = borders[i].first, r1 = borders[i].second;
int l2 = borders[i+1].first, r2 = borders[i+1].second;
if(l1 < r1 && l2 < r2 && abs(r1-l2) < 2){
res[r1] = '_';
}
}
return res;
}
# | 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... |