# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1047145 | pawned | Paint By Numbers (IOI16_paint) | C++17 | 230 ms | 420 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.
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
#include "paint.h"
string solve_puzzle(string s, vi c) {
int N = s.size();
int K = c.size();
// try all combinations of _ and X
// check if each works
string ans(N, '!');
for (int i = 0; i < (1 << N); i++) {
string t;
for (int j = 0; j < N; j++) {
if (i & (1 << j))
t += 'X';
else
t += '_';
}
bool can = true;
for (int j = 0; j < N; j++) {
if (s[j] != '.' && t[j] != s[j])
can = false;
}
if (!can)
continue;
// find all component sizes
vi res;
int cs = 0; // current comp size
for (int j = 0; j < N; j++) {
if (t[j] == 'X') {
cs++;
}
else {
if (cs != 0)
res.pb(cs);
cs = 0;
}
}
if (cs != 0)
res.pb(cs);
if (res.size() != K)
continue;
bool works = true;
for (int j = 0; j < K; j++) {
if (res[j] != c[j]) {
works = false;
break;
}
}
if (works) {
// cout<<"t: "<<t<<endl;
for (int j = 0; j < N; j++) {
if (ans[j] == '!') {
ans[j] = t[j];
}
else if (ans[j] == 'X') {
if (t[j] == '_')
ans[j] = '?';
}
else if (ans[j] == '_') {
if (t[j] == 'X')
ans[j] = '?';
}
}
}
}
return ans;
}
Compilation message (stderr)
# | 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... |