이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
#define ln '\n'
//#define int long long
template <class _T>
bool chmin(_T &x, const _T &y){
bool flag = false;
if ( x > y ){
x = y; flag |= true;
}
return flag;
}
template <class _T>
bool chmax(_T &x, const _T &y){
bool flag = false;
if ( x < y ){
x = y; flag |= true;
}
return flag;
}
string solve_puzzle(string s, vector<int> c) {
int n = (int)s.size(), m = (int)c.size();
auto ok = [&](string s){
vector <vector<int>> dp(n + 1, vector <int> (m + 1));
dp[0][0] = true;
vector <int> pf(n + 1);
for ( int i = 0; i < n; i++ ){
pf[i + 1] = pf[i] + (s[i] == '_');
}
auto get = [&](int l, int r){
return pf[r] - pf[l - 1];
};
s = '#' + s;
for ( int i = 1; i <= n; i++ ){
for ( int j = 0; j <= m; j++ ){
if ( s[i] != 'X' ){
dp[i][j] |= dp[i - 1][j];
}
if ( !j ) continue;
int k = i - c[j - 1];
if ( k >= 0 && !get(k + 1, i) ){
if ( !k and j <= 1 ){
dp[i][j] = true;
} else if ( k and s[k] != 'X' ){
dp[i][j] |= dp[k - 1][j - 1];
}
}
}
}
return dp[n][m];
};
string ans = s;
for ( int i = 0; i < n; i++ ){
if ( s[i] != '.' ){
continue;
}
for ( auto j: {'_', 'X'} ){
s[i] = j;
if ( ok(s) ){
if ( ans[i] != '.' ){
ans[i] = '?';
} else ans[i] = j;
}
}
s[i] = '.';
}
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... |