이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
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);
rec(x - 1, idx);
}
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] == '_';
if (s[i] == '.') ans += '?';
else ans += s[i];
}
// cout << ans<< endl;
for (int i = n - 1;i > 0;i--)
rec(i, t - 1);
// for (int i = 0;i < t;i++)
// cout << l[i]<< " "<< r[i]<< endl;
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] + 1;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... |