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, 0);
int num = k-i;
if(left >= (curr + max(0, i-1)) && right >= ((tot-curr-c[i])+(max(0,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(0, i-1)) && right >= (tot-curr+(max(0,num-1)))){
valid = true;
break;
}
curr+= c[i];
}
if(left >= (curr + max(0, 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;
}
Compilation message (stderr)
paint.cpp:18:17: warning: overflow in conversion from 'double' to 'int' changes value from '2.0e+15' to '2147483647' [-Woverflow]
18 | const int INF = 2e15;
| ^~~~
# | 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... |