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 <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define mp make_pair
#define pub push_back
#define pob pop_back()
#define ss second
#define ff first
#define mt make_tuple
#define pof pop_front()
#define fbo find_by_order
#define ook order_of_key
#define lb lower_bound
#define ub upper_bound
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
using pll = pair <ll, ll>;
using pii = pair <int, int>;
bool dp[200005][101], rdp[200005][101], canw[200005];
int wh[200005], canb[200005];
string ans;
string solve_puzzle(string s, vector<int> c) {
c.insert(c.begin(), 0);
s = '0' + s + '0';
for (int i = 1; i < s.size(); i++) {
wh[i] = wh[i - 1];
if ( s[i] == '_' )
wh[i]++;
}
for (int i = 0; i < s.size(); i++) {
if ( s[i] == 'X' )
break;
dp[i][0] = 1;
}
for (int i = 1; i < s.size(); i++) {
for (int j = 1; j < c.size(); j++) {
if ( s[i] == '_' )
dp[i][j] = dp[i - 1][j];
else if ( s[i] == 'X' ) {
if ( i >= c[j] && s[i - c[j]] != 'X' && dp[max(i - c[j] - 1, 0)][j - 1] && wh[i] - wh[i - c[j]] == 0 )
dp[i][j] = 1;
} else {
if ( dp[i - 1][j] || (i >= c[j] && s[i - c[j]] != 'X' && dp[max(i - c[j] - 1, 0)][j - 1] && wh[i] - wh[i - c[j]] == 0) )
dp[i][j] = 1;
}
}
}
for (int i = s.size(); i >= 0; i--) {
if ( s[i] == 'X' )
break;
rdp[i][0] = 1;
}
for (int i = s.size() - 2; i >= 0; i--) {
for (int j = 1; j < c.size(); j++) {
if ( s[i] == '_' )
rdp[i][j] = rdp[i + 1][j];
else if ( s[i] == 'X' ) {
if ( s.size() - i - 1 >= c[c.size() - j] )
if ( s[min(i + c[c.size() - j], (int)s.size() - 1)] != 'X' && rdp[min(i + c[c.size() - j] + 1, (int)s.size() - 1)][j - 1] && wh[i + c[c.size() - j] - 1] - wh[i - 1] == 0 )
rdp[i][j] = 1;
} else {
if ( rdp[i + 1][j] || (s.size() - i - 1 >= c[c.size() - j] && s[i + c[c.size() - j]] != 'X' && rdp[min(i + c[c.size() - j] + 1, (int)s.size() - 1)][j - 1] && wh[i + c[c.size() - j] - 1] - wh[i - 1] == 0) )
rdp[i][j] = 1;
}
}
}
for (int i = 1; i < s.size() - 1; i++)
for (int j = 0; j < c.size(); j++)
if ( s[i] != 'X' && dp[i - 1][j] && rdp[i + 1][c.size() - j - 1] )
canw[i] = 1;
for (int i = 1; i < s.size() - 1; i++)
for (int j = 1; j < c.size(); j++)
if ( i >= c[j] && wh[i] - wh[i - c[j]] == 0 && s[i - c[j]] != 'X' && dp[max(i - c[j] - 1, 0)][j - 1] && s[i + 1] != 'X' && rdp[min(i + 2, (int)s.size() - 1)][c.size() - j - 1] )
canb[i]++, canb[i - c[j]]--;
for (int i = s.size() - 1; i > 0; i--)
canb[i] += canb[i + 1];
for (int i = 1; i < s.size() - 1; i++) {
if ( canw[i] && canb[i] )
ans += '?';
else if ( canw[i] )
ans += '_';
else
ans += 'X';
}
return ans;
}
Compilation message (stderr)
paint.cpp: In function 'std::__cxx11::string solve_puzzle(std::__cxx11::string, std::vector<int>)':
paint.cpp:33:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < s.size(); i++) {
~~^~~~~~~~~~
paint.cpp:40:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < s.size(); i++) {
~~^~~~~~~~~~
paint.cpp:47:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < s.size(); i++) {
~~^~~~~~~~~~
paint.cpp:48:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 1; j < c.size(); j++) {
~~^~~~~~~~~~
paint.cpp:72:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 1; j < c.size(); j++) {
~~^~~~~~~~~~
paint.cpp:77:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if ( s.size() - i - 1 >= c[c.size() - j] )
paint.cpp:82:45: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if ( rdp[i + 1][j] || (s.size() - i - 1 >= c[c.size() - j] && s[i + c[c.size() - j]] != 'X' && rdp[min(i + c[c.size() - j] + 1, (int)s.size() - 1)][j - 1] && wh[i + c[c.size() - j] - 1] - wh[i - 1] == 0) )
paint.cpp:88:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < s.size() - 1; i++)
~~^~~~~~~~~~~~~~
paint.cpp:89:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < c.size(); j++)
~~^~~~~~~~~~
paint.cpp:93:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < s.size() - 1; i++)
~~^~~~~~~~~~~~~~
paint.cpp:94:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 1; j < c.size(); j++)
~~^~~~~~~~~~
paint.cpp:102:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < s.size() - 1; i++) {
~~^~~~~~~~~~~~~~
# | 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... |