# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
51583 | MatheusLealV | Paint By Numbers (IOI16_paint) | C++17 | 1179 ms | 51900 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.
#include "paint.h"
#include <bits/stdc++.h>
#define N 200050
using namespace std;
int n, k, branco[N], preto[N];
int qbranco(int l, int r)
{
if(!l) return branco[r];
return branco[r] - branco[l - 1];
}
int qpreto(int l, int r)
{
if(!l) return preto[r];
return preto[r] - preto[l - 1];
}
char s[N];
int W[N], B[N];
bool L[N][120], R[N][120];
string solve_puzzle(string S, vector<int> c)
{
n = S.size(), k = c.size();
n ++;
s[n] = '_';
for(int i = 1; i < n; i++) s[i] = S[i - 1];
for(int i = 1; i <= n; i++)
{
preto[i] = preto[i - 1] + (s[i] == 'X');
branco[i] = branco[i - 1] + (s[i] == '_');
}
L[0][0] = 1;
for(int q = 0; q <= k; q++)
{
for(int i = 1; i <= n; i++)
{
if(s[i] == 'X') continue;
L[i][q] = L[i - 1][q];
if(q > 0 and i - c[q - 1] - 1 >= 0 and !qbranco(i - c[q - 1], i - 1)) L[i][q] |= L[i - c[q - 1] - 1][q - 1];
}
}
R[n + 1][k] = 1;
for(int q = k; q >= 0; q--)
{
for(int i = n; i >= 1; i--)
{
if(s[i] != 'X') R[i][q] = R[i + 1][q];
if(q < k and i + c[q] <= n and !qbranco(i, i + c[q] - 1) and s[i + c[q]] != 'X') R[i][q] |= R[i + c[q] + 1][q + 1];
}
}
for(int i = 1; i < n; i++)
for(int q = 0; q <= k; q++)
if(L[i][q] and R[i + 1][q] and s[i] != 'X') W[i] = 1;
for(int q = 1; q <= k; q++)
{
for(int i = 1; i <= n; i++)
{
if(i + c[q - 1] > n) continue;
if(L[i - 1][q - 1] and R[i + c[q - 1] + 1][q] and s[i - 1] != 'X' and s[i + c[q - 1]] != 'X' and !qbranco(i, i + c[q - 1] - 1))
{
B[i] ++;
B[i + c[q - 1]] --;
}
}
}
string ans;
for(int i = 1; i < n; i++)
{
B[i] += B[i - 1];
if(W[i] and B[i]) ans.push_back('?');
else if(W[i]) ans.push_back('_');
else if(B[i]) ans.push_back('X');
else ans.push_back('?');
}
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... |