이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <cstdlib>
#include <deque>
#include <cassert>
#include "paint.h"
using namespace std;
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
const int N = 2e5 + 15;
const int K = 1e2 + 15;
int n, k, p[2][N], a[K], pref[2][N], dp[N][K];
inline int get_black(int l, int r) {
return p[1][r] - p[1][l-1];
}
inline int get_white(int l, int r) {
return p[0][r] - p[0][l-1];
}
inline void add_black(int l, int r) {
++pref[1][l];
--pref[1][r+1];
}
inline void add_white(int l, int r) {
++pref[0][l];
--pref[0][r+1];
}
int rec(int pos, int block) {
if(block == k) {
if(get_black(pos + a[block], n) == 0) {
add_white(pos + a[block], n);
return dp[pos][block] = 1;
}
return dp[pos][block] = 2;
}
if(dp[pos][block])
return dp[pos][block];
dp[pos][block] = 2;
for(int i = pos + a[block] + 1; i + a[block + 1] - 1 <= n; ++i)
if(!get_white(i, i + a[block + 1] - 1) && !get_black(pos + a[block], i - 1) && rec(i, block + 1) == 1) {
add_black(pos, pos + a[block] - 1);
add_black(i, i + a[block+1] - 1);
add_white(pos + a[block], i - 1);
dp[pos][block] = 1;
}
return dp[pos][block];
}
string solve_puzzle(string s, vector<int> c) {
string ans = "";
n = s.size(); k = c.size();
s = '#' + s;
for(int i = 1; i <= n; ++i)
p[0][i] = p[0][i-1] + (s[i] == '_'),
p[1][i] = p[1][i-1] + (s[i] == 'X');
for(int i = 0; i < k; ++i)
a[i+1] = c[i];
for(int i = 1; i <= n; ++i)
if(!p[1][i-1] && i + a[1] - 1 <= n && !get_white(i, i + a[1] - 1) && rec(i, 1) == 1) {
add_white(1, i-1);
add_black(i, i + a[1] - 1);
}
for(int i = 1; i <= n; ++i)
for(int j = 0; j < 2; ++j)
pref[j][i] += pref[j][i-1];
for(int i = 1; i <= n; ++i)
pref[0][i] += (s[i] == '_'),
pref[1][i] += (s[i] == 'X');
for(int i = 1; i <= n; ++i) {
if(pref[1][i] && pref[0][i])
ans += '?';
else if(pref[1][i])
ans += 'X';
else
ans += '_';
}
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... |