# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
362237 | knightron0 | 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 <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
#define clr(a, x) memset(a, x, sizeof(a))
#define dbg(x) cout<<"("<<#x<<"): "<<x<<endl;
#define printvector(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define all(v) v.begin(), v.end()
#define lcm(a, b) (a * b)/__gcd(a, b)
#define int long long int
#define printvecpairs(vec) for(auto it: vec) cout<<it.fr<<' '<<it.sc<<endl;
#define endl '\n'
#define float long double
const int MOD = 1e9 + 7;
const int INF = 2e15;
const int MAXN = 1e5 + 5;
bool check(int idx, vector<int> c, bool which, string s){
// which = 0, if checking empty
// which = 1, if checking filled
int n = s.length();
int k= c.size();
if(which){
int tot = 0;
for(int i= 0;i<k;i++) tot += c[i];
bool valid = false;
int curr = 0;
for(int i= 0;i<k;i++){
for(int x = -1;x<=c[i];x++){
int z= x+1;
int y = c[i]-z;
if(idx-z >= 0 && idx +y < n){
int right = (n-(idx+y)-1);
int left = max(idx-z-1, 0LL);
int num = k-i;
if(left >= (curr + max(0LL, i-1)) && right >= ((tot-curr-c[i])+(max(0LL,num-1)))){
valid = true;
break;
}
}
}
if(valid){
break;
}
curr += c[i];
}
return valid;
} else {
int tot = 0;
int left = idx;
int right = n-idx-1;
for(int i= 0;i<k;i++) tot += c[i];
int curr = 0;
bool valid = false;
for(int i= 0;i<k;i++){
int num = k-i;
if(left >= (curr + max(0LL, i-1)) && right >= (tot-curr+(max(0LL,num-1)))){
valid = true;
break;
}
curr+= c[i];
}
if(left >= (curr + max(0LL, k-1)) && right >= (tot-curr)){
valid = true;
}
return valid;
}
}
string solve_puzzle(string s, vector<int> c){
int n = s.length();
string res = "";
for(int i= 0;i<n;i++){
bool empty = check(i, c, 0, s);
bool fill = check(i, c, 1, s);
if(empty && fill){
res += "?";
} else {
if(empty){
res += "_";
} else {
res += "X";
}
}
}
return res;
}