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>
using namespace std;
int L[200050][120], R[200050][120], n, k, white[200050], black[200050], qtd[200050];
int global[200050];
char ans[200050];
vector<int> pos[120];
int qblack(int l, int r) {
if(l > r) return 0;
return black[r] - (l > 0 ? black[l - 1] : 0);
}
int qwhite(int l, int r){
if(l > r) return 0;
return white[r] - (l > 0 ? white[l - 1] : 0);
}
string solve_puzzle(string s, vector<int> c)
{
n = s.size(), k = c.size();
for(int i = 0; i < n; i++)
{
white[i] = (i > 0 ? white[i - 1] : 0);
black[i] = (i > 0 ? black[i - 1] : 0);
if(s[i] == '_') white[i] ++;
if(s[i] == 'X') black[i] ++;
}
for(int q = 0; q < k; q++)
{
for(int i = 0; i < n; i++)
{
int ini = i - c[q] + 1;
if(ini < 0) continue;
bool tem = ( !q and (qblack(0, ini - 1) == 0) );
for(int j = 0; j < ini - 1; j++)
if(!tem and L[j][q - 1] and qblack(j + 1, ini - 1) == 0 ) tem = true;
if(tem and qwhite(ini, i) == 0) L[i][q] = true;
//cout<<"LLLL "<<i<<" "<<q<<" "<<L[i][q]<<"\n";
}
}
for(int q = k - 1; q >= 0; q--)
{
for(int i = n - 1; i >= 0; i--)
{
int fim = i + c[q] - 1;
if(fim >= n) continue;
bool tem = ((q == (k - 1)) and (qblack(fim + 1, n - 1) == 0));
for(int j = n - 1; j > fim + 1; j--)
if(!tem and R[j][q + 1] and qblack(fim + 1, j - 1) == 0) tem = true;
if(tem and qwhite(i, fim) == 0) R[i][q] = true;
//cout<<"RRR "<<i<<" "<<q<<" "<<R[i][q]<<"\n";
}
}
for(int q = 0; q < k; q++)
for(int i = 0; i < n; i++)
if(i - c[q] + 1 >= 0 and L[i][q] and R[i - c[q] + 1][q]) pos[q].push_back(i - c[q] + 1);
for(int q = 0; q < k; q++)
{
memset(qtd, 0, sizeof qtd);
for(auto i: pos[q])
{
qtd[i] ++;
qtd[i + c[q]] --;
global[i] ++;
global[i + c[q]] --;
}
for(int i = 1; i < n; i++) qtd[i] += qtd[i - 1];
for(int i = 0; i < n; i++)
if(qtd[i] == pos[q].size())ans[i] = 'X';
}
string resp;
for(int i = 1; i < n; i++) global[i] += global[i - 1];
for(int i = 0; i < n; i++)
{
char p = '?';
if(!global[i] and ans[i] != 'X') p = '_';
else if(ans[i] == 'X') p = 'X';
resp.push_back(p);
}
return resp;
}
Compilation message (stderr)
paint.cpp: In function 'std::__cxx11::string solve_puzzle(std::__cxx11::string, std::vector<int>)':
paint.cpp:100:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(qtd[i] == pos[q].size())ans[i] = 'X';
~~~~~~~^~~~~~~~~~~~~~~~
# | 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... |