이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "paint.h"
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i=0; i<(n); i++)
#define INF 1145141919
int N, K;
int C[100];
bool dpL[200010][101], dpR[200010][101];
int white[200010], black[200010];
inline int range_white(int l, int r) { return white[r]-(l>0?white[l-1]:0); }
inline int range_black(int l, int r) { return black[r]-(l>0?black[l-1]:0); }
int W[101];
string solve_puzzle(string S, vector<int> c) {
S = '_'+S+'_';
N = S.length();
K = c.size();
rep(i, K) C[i] = c[i];
string O(S);
rep(i, N+1) rep(j, K+1) dpL[i][j] = false, dpR[i][j] = false;
rep(i, N) white[i] = S[i]=='_', black[i] = S[i]=='X';
rep(i, N-1) white[i+1] += white[i], black[i+1] += black[i];
dpL[0][0] = true;
rep(i, N) {
if (range_black(i, i)) continue;
rep(k, K+1) dpL[i+1][k] |= dpL[i][k];
rep(k, K) {
int l = i-C[k];
if (range_white(l, i-1) == 0) dpL[i+1][k+1] |= dpL[l][k];
}
}
assert(dpL[N][K]);
dpR[N-1][K] = true;
for (int i=N-1; i>0; i--) {
if (range_black(i, i)) continue;
rep(k, K+1) dpR[i-1][k] |= dpR[i][k];
for (int k=1; k<=K; k++) {
int r = i+C[k-1];
if (range_white(i+1, r) == 0) dpR[i-1][k-1] |= dpR[r][k];
}
}
rep(i, K) W[i] = -INF;
rep(i, N) {
bool can_be_white = false, can_be_black = false;
rep(k, K) {
int pos = i-1, c = C[k];
if (pos+c<N && range_white(pos+1, pos+c)==0 && dpL[pos+1][k] && dpR[pos+c][k+1]) W[k] = pos;
can_be_black |= (i-C[k]) <= W[k];
}
if (S[i] != '.') continue;
rep(k, K+1) can_be_white |= dpL[i+1][k] && dpR[i-1][k];
//cout<<"i="<<i<<": white="<<can_be_white<<", black="<<can_be_black<<"\n";
assert(can_be_white || can_be_black);
if (!can_be_white) O[i] = 'X';
else if (!can_be_black) O[i] = '_';
else O[i] = '?';
}
O.erase(O.begin()), O.pop_back();
return O;
}
# | 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... |