This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
#define N 200005
int n, t, ok, now, cnt[N], l[105], r[105], dp[N][105];
string ans, st;
vector <int> ve;
void rec(int x, int idx){
if (dp[x][idx] != -1) return;
if (!idx){
if (x + 1 >= ve[0] && !cnt[x - ve[0]] && (idx != t - 1 || !(cnt[n - 1] - cnt[x])) ) {
dp[x][idx] = 1;
r[idx] = max(r[idx], x);
l[idx] = min(l[idx], x);
}
else dp[x][idx] = 0;
return;
}
rec(x - 1, idx);
if (st[x - ve[idx]] != 'X')
rec(x - ve[idx] - 1, idx - 1);
else dp[x - ve[idx]][idx] = 0;
if (x + 1 >= ve[idx] && dp[x - ve[idx]][idx - 1]&& !(cnt[x] - cnt[x - ve[idx]]) && (idx != t - 1 || !(cnt[n - 1] - cnt[x])) ){
if (st[x + 1] != 'X') dp[x + 1][idx] = 1;
r[idx] = max(r[idx], x);
l[idx] = min(l[idx], x);
}
else dp[x][idx] = 0;
}
string solve_puzzle(string s, vector<int> c) {
st = s;
ve = c;
n = s.size();
t = c.size();
for (int i = 0;i < t;i++)
l[i] = n;
now = 0;
memset(dp, -1, sizeof dp);
for (int i = 0;i < n;i++){
cnt[i] = cnt[i - 1] + s[i - 1] == '_';
ans += '?';
}
rec(n - 1, t - 1);
for (int i = 0;i <= l[0] - ve[0];i++)
ans[i] = '_';
for (int i = r[t - 1] + 1; i < n;i++)
ans[i] = '_';
for (int i = 0;i < t;i++){
if (i)
for (int j = r[i - 1] + 1;j <= l[i] - ve[i];j++)
ans[j] = '_';
for (int j = r[i] - ve[i];j < l[i];j++)
ans[j] = '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... |