이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;
const int INF=0x3f3f3f3f;
const int N=2e5+2;
const int K=102;
int n, k;
int dp[N][K];
int pref[2][N];
int crn[N], bel[N];
string res;
#define DEBUG 0
string solve_puzzle(string s, vector<int> c) {
n=s.size(); k=c.size();
s=" "+s;
pref[0][0]=pref[1][0]=0;
for (int i=1; i<=n; ++i) {
pref[0][i]=pref[0][i-1]+(s[i]=='_');
pref[1][i]=pref[1][i-1]+(s[i]=='X');
}
memset(dp, 0, sizeof dp);
memset(crn, 0, sizeof crn);
memset(bel, 0, sizeof bel);
dp[0][0]=1;
for (int i=1; i<=n; ++i) {
if (s[i]!='X') dp[i][0]=dp[i-1][0];
for (int j=1; j<=k; ++j) {
if (s[i]!='X') dp[i][j]|=dp[i-1][j];
if (i>=c[j-1] && pref[0][i]-pref[0][i-c[j-1]]==0 && s[i-c[j-1]]!='X') dp[i][j]|=dp[i-c[j-1]-(j>1)][j-1];
}
}
#if DEBUG
for (int i=k; i>=0; --i) {
for (int j=0; j<=n; ++j) {
printf("%d ", dp[j][i]);
}
printf("\n");
}
printf("----------------\n");
#endif // DEBUG
assert(dp[n][k]);
dp[n][k]++;
for (int i=n; i>0; --i) {
for (int j=0; j<=k; ++j) {
if (dp[i][j]<2) continue;
if (s[i]!='X' && dp[i-1][j]) {
dp[i-1][j]++;
bel[i]++;
}
if (j && i>=c[j-1] && pref[0][i]-pref[0][i-c[j-1]]==0 && s[i-c[j-1]]!='X' && dp[i-c[j-1]-(j>1)][j-1]) {
crn[i-c[j-1]+1]++; crn[i+1]--; bel[i-c[j-1]]++;
// printf("interval: [%d, %d]\n", i-c[j-1]+1, i);
dp[i-c[j-1]-(j>1)][j-1]++;
}
}
}
#if DEBUG
for (int i=k; i>=0; --i) {
for (int j=0; j<=n; ++j) {
printf("%d ", dp[j][i]>1 ? 1 : 0);
}
printf("\n");
}
printf("----------------\n");
#endif // DEBUG
for (int i=1; i<=n; ++i) crn[i]+=crn[i-1];
for (int i=1; i<=n; ++i) {
if (bel[i] && crn[i]) res+='?';
else if (crn[i]) res+='X';
else if (bel[i]) res+='_';
else assert(0);
}
return res;
}
# | 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... |