이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int c=200002, p=102;
int n, k, kom[c], dp[c];
string ans;
bool kezd[c][p], veg[c][p], v[c];
string solve_puzzle(string s, vector<int> sz) {
n=s.size(), k=sz.size();
s+='.';
for (int i=0; i<n; i++) kom[i+1]=(s[i]=='_')+kom[i];
kezd[0][0]=1;
for (int i=0; i<n; i++) for (int j=0; j<=k; j++) if (kezd[i][j]) {
//cout << "lehet " << i << " " << j << "\n";
if (s[i]!='X') kezd[i+1][j]=1;
if (j<k) {
int h=sz[j];
if (i+h<=n && kom[i+h]==kom[i] && s[i+h]!='X') kezd[i+h+1][j+1]=1;
}
}
veg[n][k]=1;
for (int i=n; i>=1; i--) for (int j=k; j>=0; j--) if (veg[i][j]) {
//cout << "veg " << i << " " << j << "\n";
if (s[i-1]!='X') veg[i-1][j]=1;
if (j) {
int h=sz[j-1];
if (i-h-1>=0 && kom[i]==kom[i-h] && s[i-h-1]!='X') veg[i-h-1][j-1]=1;
}
}
for (int i=n; i>=0; i--) for (int j=k; j>=0; j--) if (veg[i][j]) veg[i+1][j]=1;
/*for (int i=0; i<=n; i++) for (int j=0; j<=k; j++) {
if (veg[i][j]) cout << "vege " << i << " " << j << "\n";
if (kezd[i][j]) cout << "kezd " << i << " " << j << "\n";
}*/
for (int i=1; i<=n; i++) for (int j=0; j<=k; j++) {
if (kezd[i][j] && veg[i][j]) v[i]=1;
//if (i==1 && kezd[i][j] && veg[i][j]) cout << j << "\n";
if (j<k) {
int h=sz[j];
if (i+h<=n+1 && kom[i-1]==kom[i+h-1] && s[i+h-1]!='X' && kezd[i-1][j] && veg[i+h][j+1]) dp[i]++, dp[i+h]--;// cout << "add " << i << " " << i+h << "\n";
//cout << "valt " << i << " " << i+h << endl;
}
}
for (int i=1; i<=n; i++) {
dp[i]+=dp[i-1];
//cout << "vege " << i << " " << dp[i] << " " << v[i] << "\n";
if (v[i] && dp[i]) ans+='?';
if (v[i] && !dp[i]) ans+='_';
if (!v[i] && dp[i]) 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... |