이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
ostream& operator<<(ostream &out, string str) {
for(char c : str) out << c;
return out;
}
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
return out << "(" << p.ST << ", " << p.ND << ")";
}
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
out << "{";
for(auto it = a.begin(); it != a.end(); it = next(it))
out << (it != a.begin() ? ", " : "") << *it;
return out << "}";
}
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
cerr << a << ", ";
dump(x...);
}
#ifdef DEBUG
# define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
# define debug(...) false
#endif
template<class T> int size(T && a) { return (int) a.size(); }
using LL = long long;
using PII = pair<int, int>;
#include "paint.h"
string solve_puzzle(string s, vector<int> c) {
int n = size(s), k = size(c);
vector<int> w(n);
REP(i, n)
w[i] = (s[i] == '_') + (i != 0 ? w[i - 1] : 0);
auto get = [&](int l, int r) {
return w[r] - (l != 0 ? w[l - 1] : 0);
};
vector<vector<bool>> suff(k + 1, vector<bool>(n + 1));
suff[k][n] = true;
for(int i = k; i >= 0; i--) {
for(int j = n - 1; j >= 0; j--) {
if(s[j] != 'X' && suff[i][j + 1])
suff[i][j] = true;
if(i < k) {
int r = j + c[i] - 1;
if(n <= r || get(j, r)) continue;
if(i < k - 1 && (n <= r + 1 || s[r + 1] == 'X')) continue;
if(suff[i + 1][(i < k - 1 ? r + 1 : r) + 1])
suff[i][j] = true;
}
}
}
vector<int> f(n + 1), e(n + 1);
vector<vector<bool>> pref(k + 1, vector<bool>(n + 1));
pref[0][0] = true;
REP(i, k + 1) REP(j, n) {
if(!pref[i][j]) continue;
if(s[j] != 'X') {
pref[i][j + 1] = true;
if(suff[i][j + 1]) e[j] = true;
}
if(i < k) {
int r = j + c[i] - 1;
if(n <= r || get(j, r)) continue;
if(i < k - 1 && (n <= r + 1 || s[r + 1] == 'X')) continue;
int p = (i < k - 1 ? r + 1 : r);
pref[i + 1][p + 1] = true;
if(suff[i + 1][p + 1]) {
f[j]++, f[r + 1]--;
if(i < k - 1) e[p] = true;
}
}
}
FOR(i, 1, n)
f[i] += f[i - 1];
string ans;
REP(i, n) {
if(e[i] && f[i]) ans += "?";
else if(e[i]) ans += "_";
else ans += "X";
}
return ans;
}
# | 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... |