이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "paint.h"
#include <bits/stdc++.h>
using namespace std ;
const int N = 2e5+2 ;
int dp [ N ][ 102 ][2];
int acc [ N ], acc2[N] ;
vector<int> C ;
int couldW [N], couldB[N] ;
string S ;
int posib [ N ][ 102 ];
int tam1, tam2 ;
int ult[N] ;
int solve ( int i, int clue, int flag ) {
if ( clue == tam1 && i <= tam2 ) {
int can = (acc2[tam2-1] - (i?acc2[i-1]:0) == 0) ;
ult[i] = can ;
return can ;
}
if ( i >= tam2 ) return 0 ;
auto &rf = dp[i][clue][flag] ;
if ( rf != -1 ) return rf ;
rf = 0 ;
if ( !flag && S[i] == 'X' ) return 0 ;
if ( S[i] != 'X' && solve(i+1, clue,1) ) {
couldW[i] = 1 ;
rf = 1 ;
}
if ( flag && acc[i+C[clue]-1] - (i?acc[i-1]:0) == 0 && solve ( i+C[clue], clue+1, 0 ) ) {
posib[i][clue] = 1;
rf = 1;
}
return rf ;
}
std::string solve_puzzle(std::string s, std::vector<int> c) {
C = c ;
S = s ;
memset ( dp, -1, sizeof dp ) ;
tam1 = c.size() ;
tam2 = s.size() ;
for ( int i = 0 ; i < tam2 ; ++i ) {
if ( i ) acc[i] += acc[i-1], acc2[i] += acc2[i-1] ;
acc[i] += (s[i]=='_');
acc2[i] += (s[i]=='X') ;
}
solve ( 0, 0,1 ) ;
string ans ;
int id = 0 ;
int curMx = 0 ;
for ( int i = 0 ; i < tam2 ; ++i ) {
curMx = max ( curMx, ult[i] ) ;
couldW[i] = max ( couldW[i], curMx ) ;
}
for ( int i = 0 ; i < tam2 ; ++i ) {
id = max ( id, i ) ;
for ( int j = 0 ; j < tam1 ; ++j ) {
if ( posib[i][j] ) {
// cout << "its posible " << i << ' ' << j << '\n' ;
for ( ; id < i + c[j] ; ++id )
couldB[id] = 1;
}
}
}
for ( int i = 0 ; i < tam2 ; ++i ) {
if ( s[i] != '.' ) ans.push_back (s[i]) ;
else {
if ( couldB[i] && couldW[i] ) ans.push_back ('?') ;
else if ( couldB[i] ) ans.push_back ('X');
else ans.push_back ('_') ;
}
}
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... |