# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
170525 | AlexLuchianov | Paint By Numbers (IOI16_paint) | C++14 | 497 ms | 17264 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 <bitset>
#include <cstdlib>
#include <iostream>
int const nmax = 200000;
int const cluesmax = 100;
std::bitset<1 + cluesmax> dp[1 + nmax][2];
std::bitset<1 + cluesmax> dp2[1 + nmax][2];
int white[1 + nmax], black[1 + nmax];
int getsum(int x, int y){
if(0 == x)
return white[y];
else
return white[y] - white[x - 1];
}
int canbeblack[1 + nmax], canbewhite[1 + nmax];
std::string solve_puzzle(std::string s, std::vector<int> clue) {
int n = s.size();
std::vector<int> clue2;
clue2.push_back(0);
for(int i = 0; i < clue.size(); i++)
clue2.push_back(clue[i]);
clue = clue2;
s = "#" + s;
dp[0][0][0] = 1;
for(int i = 1;i <= n; i++) {
white[i] = white[i - 1] + (s[i] == '_');
black[i] = black[i - 1] + (s[i] == 'X');
}
for(int i = 1;i <= n; i++){
for(int j = 0;j < clue.size(); j++){
if(s[i] != 'X')
dp[i][0][j] = (dp[i - 1][0][j] | dp[i - 1][1][j]);
if(0 < j && 1 <= i - clue[j] + 1 && getsum(i - clue[j] + 1, i) == 0)
dp[i][1][j] = (dp[i - clue[j]][0][j - 1]);
}
}
dp2[n + 1][0][clue.size()] = 1;
for(int i = n; 1 <= i; i--)
for(int j = 0; j <= clue.size(); j++){
if(s[i] != 'X')
dp2[i][0][j] = (dp2[i + 1][0][j] | dp2[i + 1][1][j]);
if(0 < j && j < clue.size() && i + clue[j] - 1 <= n && getsum(i, i + clue[j] - 1) == 0)
dp2[i][1][j] = (dp2[i + clue[j]][0][j + 1]);
}
for(int i = 1;i <= n; i++) {
for(int j = 0; j < clue.size(); j++){
if(dp[i][1][j] == 1 && dp2[i + 1][0][j + 1]) {
//std::cout << i << " " << j << '\n';
canbeblack[i - clue[j] + 1]++;
canbeblack[i + 1]--;
}
if(dp[i][0][j] == 1 && (dp2[i + 1][0][j + 1] | dp2[i + 1][1][j + 1]) == 1)
canbewhite[i]++;
}
}
for(int i = 1; i <= n; i++)
canbeblack[i] += canbeblack[i - 1];
std::string result;
for(int i = 1;i <= n; i++)
if(canbewhite[i] == 0)
result += 'X';
else if(canbeblack[i] == 0)
result += '_';
else
result += '?';
return result;
}
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... |