# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
362206 | knightron0 | Paint By Numbers (IOI16_paint) | C++14 | 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;
string solve_puzzle(string s, vector<int> c){
int n = s.length();
int tot = 0;
int freq_empty[n+2];
clr(freq_empty, 0);
int freq_used[n+2];
clr(freq_used, 0);
for(int mask = 0;mask<(1<<n);mask++){
bool valid = true;
vector<int> blocks;
int curr = 0;
for(int b=0;b<n;b++){
if(mask & (1<<b)){
if(s[b] == '_'){
valid = false;
break;
} else {
curr++;
continue;
}
} else {
if(s[b] == 'X'){
valid = false;
break;
} else {
if(curr!=0){
blocks.pb(curr);
}
curr = 0;
}
}
}
if(curr!=0){
blocks.pb(curr);
}
if(blocks.size() != c.size()) valid = false;
if(!valid) continue;
for(int i= 0;i<c.size();i++){
if(c[i] != blocks[i]) {
valid = 0;
break;
}
}
if(valid){
tot++;
for(int b=0;b<n;b++){
if(mask & (1<<b)){
freq_used[b]++;
} else {
freq_empty[b]++;
}
}
}
}
string res = "";
for(int b=0;b<n;b++){
if(freq_empty[b] == tot){
res += "_";
} else if(freq_used[b] == tot){
res += "X";
} else {
res += "?";
}
}
return res;
}