# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
125328 | Nodir_Bobiev | Paint By Numbers (IOI16_paint) | C++14 | 933 ms | 186496 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
# include <iostream>
# include <vector>
using namespace std;
const int N = 2e5 + 100;
string S;
vector < int > C;
int n, k;
int W[N][111], B[N][111], pfW[N], pfB[N];
int get( int l, int r, int st )
{
if( st == 0 ){
if( l )return pfW[r] - pfW[l-1];
else return pfW[r];
}else {
if( l ) return pfB[r] - pfB[l-1];
else return pfB[r];
}
}
bool rec( int i, int j, int st )
{
if( i == n ){ return (j==k); }
if( st == 0 && W[i][j] != -1 )
return W[i][j];
if( st == 1 && B[i][j] != -1 )
return B[i][j];
if( st == 0 ){
if( S[i] != 'X' )
return W[i][j] = ( rec( i+1, j, 0 ) | rec( i+1, j, 1 ) );
return W[i][j] = 0;
}
else if( st == 1 ){
if ( j < k && i+C[j] <= n && get( i, i+C[j]-1, 0 ) == 0 )
return B[i][j] = ( rec( i+C[j], j+1, 0 ) );
return B[i][j] = 0;
}
}
string solve_puzzle( string s, vector < int > c )
{
n = s.size(); k = c.size();
S = s; C = c;
for( int i = 0; i <= n; i ++ ){
for( int j = 0; j <= k; j ++ ){
W[i][j] = -1;
B[i][j] = -1;
}
}
for( int i = 0; i < n; i ++ ){
if( i ){
pfW[i] = pfW[i - 1];
pfB[i] = pfB[i - 1];
}if( S[i] == 'X' ){
pfB[i] ++;
}if( S[i] == '_' ){
pfW[i] ++;
}
}
rec( 0,0,0 );
rec( 0,0,1 );
int black_able = -1, white_able = 0;
string answer;
for( int i = 0; i < n; i ++ ){
white_able = 0;
for( int j = 0; j <= k; j ++ ){
if( B[i][j] == 1) black_able = max( black_able, i+C[j]-1);
if( W[i][j] == 1) white_able = true;
}
if( black_able >= i && white_able ){
answer += '?';
}else if( black_able >= i ){
answer += 'X';
}else if( white_able ){
answer += '_';
}
}
/*
cout << "Black :" << endl;
for( int i = 0; i <= n; i ++ ){
for( int j = 0; j <= k; j ++ ){
cout << B[i][j] << ' ';
}cout << endl;
}
cout << "White :" << endl;
for( int i = 0; i <= n; i ++ ){
for( int j = 0; j <= k; j ++ ){
cout << W[i][j] << ' ';
}
cout << endl;
}
*/
return answer;
}
/*
int main()
{
string ans;
ans = solve_puzzle( ".X........", { 3 } );
cout << ans;
return 0;
}
*/
Compilation message (stderr)
# | 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... |