# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
284641 | A02 | Paint By Numbers (IOI16_paint) | C++14 | 543 ms | 524292 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "paint.h"
#include <vector>
#include <string>
#include <set>
#include <algorithm>
#include <iostream>
using namespace std;
std::string solve_puzzle(std::string s, std::vector<int> c) {
int n = s.size();
int k = c.size();
int first_left_black = n;
for (int i = 0; i < n; i++){
if (s[i] == 'X'){
first_left_black = i;
break;
}
}
int first_right_black = -1;
for (int i = n - 1; i >= 0; i--){
if (s[i] == 'X'){
first_right_black = i;
break;
}
}
vector<vector<vector<int> > > DP_left_K (n, vector<vector<int> > (k, vector<int>()));
vector<vector<vector<int> > > DP_right_K (n, vector<vector<int> > (k, vector<int>()));
if (s[0] != '_'){
DP_left_K[0][0].push_back(1);
}
for (int N = 1; N < n; N++){
for (int K = 0; K < k; K++){
//cout << N << ' ' << K << endl;
if (s[N] != '_'){
if (K == 0 && N <= first_left_black){
DP_left_K[N][K].push_back(1);
}
if (K > 0 && DP_left_K[N-1][K-1].size() > 0 && DP_left_K[N - 1][K - 1][DP_left_K[N - 1][K - 1].size() - 1] >= c[K - 1] + 1){
DP_left_K[N][K].push_back(1);
}
for (int i = 0; i < DP_left_K[N - 1][K].size(); i++){
if (DP_left_K[N - 1][K][i] + 1 > c[K]){
break;
}
DP_left_K[N][K].push_back(DP_left_K[N - 1][K][i] + 1);
}
}
//cout << 'x' << endl;
if (s[N] != 'X'){
if (DP_left_K[N-1][K].size() > 0 && DP_left_K[N - 1][K][DP_left_K[N - 1][K].size() - 1] >= c[K]){
DP_left_K[N][K].push_back(DP_left_K[N - 1][K][DP_left_K[N - 1][K].size() - 1] + 1);
}
}
}
}
if (s[n-1] != '_'){
DP_right_K[n-1][k-1].push_back(1);
}
for (int N = n - 2; N >= 0; N--){
for (int K = k - 1; K >= 0; K--){
if (s[N] != '_'){
if (K == k - 1 && N >= first_right_black){
DP_right_K[N][K].push_back(1);
}
if (K < k - 1 && DP_right_K[N+1][K+1].size() > 0 && DP_right_K[N + 1][K + 1][DP_right_K[N + 1][K + 1].size() - 1] >= c[K + 1] + 1){
DP_right_K[N][K].push_back(1);
}
for (int i = 0; i < DP_right_K[N + 1][K].size(); i++){
if (DP_right_K[N + 1][K][i] + 1 > c[K]){
break;
}
DP_right_K[N][K].push_back(DP_right_K[N + 1][K][i] + 1);
}
}
//cout << 'x' << endl;
if (s[N] != 'X'){
if (DP_right_K[N+1][K].size() > 0 && DP_right_K[N + 1][K][DP_right_K[N + 1][K].size() - 1] >= c[K]){
DP_right_K[N][K].push_back(DP_right_K[N + 1][K][DP_right_K[N + 1][K].size() - 1] + 1);
}
}
}
}
// for (int N = 0; N < n; N++){
//
// for (int K = 0; K < k; K++){
// cout << N << ':' << K << endl << "left" << endl;
// for (int i = 0; i < DP_left_K[N][K].size(); i++){
// cout << DP_left_K[N][K][i] << ' ';
// }
// cout << endl << "right" << endl;
// for (int i = 0; i < DP_right_K[N][K].size(); i++){
// cout << DP_right_K[N][K][i] << ' ';
// }
// cout << endl << endl;
//
// }
// }
string result = s;
for (int i = 0; i < n; i++){
if (s[i] == '.'){
bool can_be_black = false;
bool can_be_white = false;
if (i < first_left_black){
if (DP_right_K[i][0].size() > 0 && DP_right_K[i][0][DP_right_K[i][0].size() - 1] > c[0]){
can_be_white = true;
}
}
if (i > first_right_black){
if (DP_left_K[i][k - 1].size() > 0 && DP_left_K[i][k - 1][DP_left_K[i][k - 1].size() - 1] > c[k - 1]){
can_be_white = true;
}
}
for (int K = 0; K < k - 1; K++){
if (DP_left_K[i][K].size() > 0 && DP_right_K[i][K + 1].size() > 0){
if (DP_left_K[i][K][DP_left_K[i][K].size() - 1] > c[K] && DP_right_K[i][K + 1][DP_right_K[i][K + 1].size() - 1] > c[K + 1]){
can_be_white = true;
}
}
}
for (int K = 0; K < k; K++){
//cout << 'p' << i << ' ' << K << endl;
if (DP_left_K[i][K].size() > 0 && DP_right_K[i][K].size() > 0){
int left_pointer = 0;
int right_pointer = DP_right_K[i][K].size() - 1;
while (left_pointer < DP_left_K[i][K].size() && right_pointer >= 0){
//cout << ' ' << DP_left_K[i][K][left_pointer] << ' ' << DP_right_K[i][K][right_pointer] << ' ' << c[K] << endl;
if (DP_left_K[i][K][left_pointer] + DP_right_K[i][K][right_pointer] == c[K] + 1){
can_be_black = true;
break;
}
if (DP_left_K[i][K][left_pointer] + DP_right_K[i][K][right_pointer] > c[K] + 1){
right_pointer--;
}
if (DP_left_K[i][K][left_pointer] + DP_right_K[i][K][right_pointer] < c[K] + 1){
left_pointer++;
}
}
}
}
if (can_be_black && can_be_white){
result[i] = '?';
} else {
if (can_be_black){
result[i] = 'X';
} else {
result[i] = '_';
}
}
}
}
return result;
}
컴파일 시 표준 에러 (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... |