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>;
int dp[100005][101], wh[100001], rdp[100005][101], canw[100005], canb[100005];
string ans;
string solve_puzzle(string s, vector<int> c) {
c.insert(c.begin(), 0);
for (int i = 1; i < s.size(); i++) {
wh[i] = wh[i - 1];
if ( s[i] == '_' )
wh[i]++;
}
s = '0' + s + '0';
for (int i = 0; i < s.size(); i++) {
if ( s[i] == 'X' )
break;
dp[i][0] = 1;
}
for (int j = 1; j < s.size(); j++) {
for (int i = 1; i < c.size(); i++) {
if ( s[j] == '_' )
dp[j][i] = dp[j - 1][i];
else if ( s[j] == 'X' ) {
if ( j >= c[i] && s[j - c[i]] != 'X' && dp[max(j - c[i] - 1, 0)][i - 1] )
dp[j][i] = 1;
} else {
if ( dp[j - 1][i] || (j >= c[i] && s[j - c[i]] != 'X' && dp[max(j - c[i] - 1, 0)][i - 1]) )
dp[j][i] = 1;
}
}
}
for (int i = s.size(); i >= 0; i--) {
if ( s[i] == 'X' )
break;
rdp[i][0] = 1;
}
for (int j = s.size() - 1; j > 0; j--) {
for (int i = 1; i < c.size(); i++) {
if ( s[j] == '_' )
rdp[j][i] = rdp[j + 1][i];
else if ( s[j] == 'X' ) {
if ( s.size() - j >= c[c.size() - i] )
if ( s[min(j + c[c.size() - i], (int)s.size())] != 'X' && rdp[min(j + c[c.size() - i] + 1, (int)s.size())][i - 1] )
rdp[j][i] = 1;
} else {
if ( rdp[j + 1][i] || (s.size() - j >= c[c.size() - i] && s[min(j + c[c.size() - i], (int)s.size())] != 'X' && rdp[min(j + c[c.size() - i] + 1, (int)s.size())][i - 1]) )
rdp[j][i] = 1;
}
}
}
for (int i = 1; i < s.size(); 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(); 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[max(i + 2, (int)s.size())][c.size() - j - 1] )
canb[i]++, canb[max(i - c[j], 0)]--;
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:30:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < s.size(); i++) {
~~^~~~~~~~~~
paint.cpp:39:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < s.size(); i++) {
~~^~~~~~~~~~
paint.cpp:46:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 1; j < s.size(); j++) {
~~^~~~~~~~~~
paint.cpp:47:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < c.size(); i++) {
~~^~~~~~~~~~
paint.cpp:71:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < c.size(); i++) {
~~^~~~~~~~~~
paint.cpp:76:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if ( s.size() - j >= c[c.size() - i] )
paint.cpp:80:41: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if ( rdp[j + 1][i] || (s.size() - j >= c[c.size() - i] && s[min(j + c[c.size() - i], (int)s.size())] != 'X' && rdp[min(j + c[c.size() - i] + 1, (int)s.size())][i - 1]) )
paint.cpp:86:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < s.size(); i++)
~~^~~~~~~~~~
paint.cpp:87:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < c.size(); j++)
~~^~~~~~~~~~
paint.cpp:91:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < s.size(); i++)
~~^~~~~~~~~~
paint.cpp:92:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 1; j < c.size(); j++)
~~^~~~~~~~~~
paint.cpp:100: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... |