# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
67407 | mirbek01 | Paint By Numbers (IOI16_paint) | C++17 | 0 ms | 0 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 "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
int n, k;
string solve_puzzle(string s, vector<int> c) {
n = (int)(s.size());
k = (int)(c.size());
string ans, t;
int sum = 0;
for(int i = 0; i < k; i ++)
sum += c[i];
sum += max(0, k - 1);
if(sum == n){
for(int i = 0; i < k; i ++){
for(int j = 0; j < c[i]; j ++){
ans += 'X';
}
if(i != k - 1){
ans += '_';
}
}
} else {
vector <int> v;
int pos = 0;
for(int i = 0; i < k; i ++){
for(int j = 0; j < n; j ++){
bool fl = 1;
for(int w = pos + j, cn = 0; cn < c[i]; w ++, cn ++){
if(s[w] != '.') {
fl = 0;
break;
}
}
if(fl){
v.push_back(pos + j);
pos = pos + j + c[i] + 1;
break;
}
}
}
ans = s;
t = s;
for(int i = k - 1; i >= 0; i --){
int mx = 0, all = 0;
int cnt[n];
memset(cnt, 0, sizeof(cnt));
for(int j = v[i]; j + c[i] - 1 < n; j ++){
bool fl = 1;
for(int w = j, cn = 0; cn < c[i]; w ++, cn ++){
if(t[w] != '.'){
fl = 0;
break;
}
if(cn == c[i] - 1){
if(w + 1 < n && t[w + 1] == 'X') fl = 0;
}
}
if(fl){
all ++;
for(int w = j, cn = 0; cn < c[i]; w ++, cn ++){
cnt[w] ++;
}
mx = j;
}
}
for(int j = v[i]; j < mx + c[i]; j ++){
if(cnt[j] == all){
ans[j] = 'X';
} else if(cnt[j])
ans[j] = '?';
else
ans[j] = '_';
}
for(int j = mx, cn = 0; cn < c[i]; j ++, cn ++){
t[j] = 'X';
}
}
}
for(int i = 0; i < n; i ++){
if(ans[i] == '.') asn[i] = '_';
}
return ans;
}