# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
593132 | Josia | Paint By Numbers (IOI16_paint) | C++14 | 728 ms | 109380 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "paint.h"
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> blocks;
vector<int> canBeBlack;
vector<int> canBeWhite;
vector<int> blackRequirement;
vector<int> whiteRequirement;
vector<vector<int>> mem;
bool dp(int i, int k) {
if ((i<0) || (k>0 && i==0)) return 0;
if (k==0) {
if (blackRequirement[i] != 0) return 0;
canBeWhite[0]++;
canBeWhite[i]--;
return 1;
}
assert(i>0 && k>0);
if (mem[i][k] != -1) return mem[i][k];
pair<int, int> nextBlock; // range (both inclusive)
nextBlock.second = i-1;
nextBlock.first = i-blocks[k-1];
int empty = i-blocks[k-1]-1;
bool poss = 0;
if (blackRequirement[i]-blackRequirement[i-1] == 0 && dp(i-1, k)) {
poss=1;
canBeWhite[i-1]++;
canBeWhite[i]--;
}
if (nextBlock.first >= 0 && whiteRequirement[nextBlock.second+1]-whiteRequirement[nextBlock.first] == 0) {
if (empty >= 0 && blackRequirement[empty+1]-blackRequirement[empty] != 0) {
return mem[i][k] = poss;
}
if (nextBlock.first > 0 && (!dp(nextBlock.first-1, k-1))) return mem[i][k] = poss;
if (nextBlock.first == 0 && k > 1) return mem[i][k] = poss;
poss = 1;
if (empty >= 0) {
canBeWhite[empty]++;
canBeWhite[empty+1]--;
}
canBeBlack[nextBlock.first]++;
canBeBlack[nextBlock.second+1]--;
}
return mem[i][k] = poss;
}
std::string solve_puzzle(std::string s, std::vector<int> c) {
n = s.size();
canBeBlack.assign(n+2, 0);
canBeWhite.assign(n+2, 0);
blocks = c;
blackRequirement = {0};
whiteRequirement = {0};
for (int i = 0; i<n; i++) {
blackRequirement.push_back(blackRequirement.back());
whiteRequirement.push_back(whiteRequirement.back());
if (s[i] == 'X') blackRequirement.back()++;
if (s[i] == '_') whiteRequirement.back()++;
}
mem.assign(n+2, vector<int>(c.size()+2, -1));
dp(n, c.size());
string res;
int black = 0;
int white = 0;
for (int i = 0; i<n; i++) {
black += canBeBlack[i];
white += canBeWhite[i];
if (black && white) res.push_back('?');
else if (black) res.push_back('X');
else if (white) res.push_back('_');
else res.push_back('%');
}
return res;
}
컴파일 시 표준 에러 (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... |