int vis[ 1000 ] [ 1000 ] ,comp[ 1000 ] [ 1000 ] ;
int dx[ ] = { - 1 ,1 ,0 ,0 } ;
int dy[ ] = { 0 ,0 ,1 ,- 1 } ;
int pqr[ 1000005 ] ;
int n,m;
vector< vector< char >> arr;
bool check( int x, int y)
{
if ( x>= 0 && x< n&& y>= 0 && y< m&& arr[ x] [ y] == 'O' &&! vis[ x] [ y] )
return true ;
return false ;
}
void dfs( int x, int y,int id)
{
{
vis[ x] [ y] = 1 ;
comp[ x] [ y] = id;
for ( int i= 0 ; i< 4 ; i++ )
{
int xx = x + dx[ i] ;
int yy = y + dy[ i] ;
if ( check( xx,yy) )
dfs( xx,yy,id) ;
}
}
}
void flip( int x,int y)
{
if ( comp[ x] [ y] &&! pqr[ comp[ x] [ y] ] )
arr[ x] [ y] = 'X' ;
}
void solve( )
{
memset ( vis, 0 , sizeof ( vis) ) ;
memset ( comp,0 ,sizeof ( comp) ) ;
memset ( pqr,0 ,sizeof ( pqr) ) ;
n = A.size ( ) ;
m = A[ 0 ] .size ( ) ;
int id= 1 ;
for ( int i= 0 ; i< n; i++ )
for ( int j= 0 ; j< m; j++ )
{
if ( check( i,j) )
{ dfs( i,j,id) ;
id++ ; }
}
for ( int i= 0 ; i< n; i++ )
{
if ( i== 0 || i== n- 1 )
{
for ( int j= 0 ; j< m; j++ )
pqr[ comp[ i] [ j] ] = 1 ;
}
else
{
pqr[ comp[ i] [ 0 ] ] = 1 ;
pqr[ comp[ i] [ m- 1 ] ] = 1 ;
}
}
for ( int i= 0 ; i< n; i++ )
for ( int j= 0 ; j< m; j++ )
{
flip( i,j) ;
}
}
aW50IHZpc1sxMDAwXVsxMDAwXSxjb21wWzEwMDBdWzEwMDBdOwppbnQgZHhbXT17LTEsMSwwLDB9OwppbnQgZHlbXT17MCwwLDEsLTF9OwppbnQgcHFyWzEwMDAwMDVdOwppbnQgbixtOwp2ZWN0b3I8dmVjdG9yPGNoYXI+PmFycjsKYm9vbCBjaGVjayhpbnQgeCwgaW50IHkpCnsKICAgIGlmKHg+PTAmJng8biYmeT49MCYmeTxtJiZhcnJbeF1beV09PSdPJyYmIXZpc1t4XVt5XSkKICAgICAgICByZXR1cm4gdHJ1ZTsKICAgIHJldHVybiBmYWxzZTsKfQp2b2lkIGRmcyhpbnQgeCwgaW50IHksaW50IGlkKQp7CiAgICAKICAgIHsKICAgICAgICB2aXNbeF1beV09MTsKICAgICAgICBjb21wW3hdW3ldID0gaWQ7CiAgICAgICAgZm9yKGludCBpPTA7aTw0O2krKykKICAgICAgICB7CiAgICAgICAgICAgIGludCB4eCA9IHggK2R4W2ldOwogICAgICAgICAgICBpbnQgeXkgPSB5ICtkeVtpXTsKICAgICAgICAgICAgaWYoY2hlY2soeHgseXkpKQogICAgICAgICAgICAgICAgZGZzKHh4LHl5LGlkKTsKICAgICAgICB9CiAgICB9Cn0Kdm9pZCBmbGlwKGludCB4LGludCB5KQp7CiAgICBpZihjb21wW3hdW3ldJiYhcHFyW2NvbXBbeF1beV1dKQogICAgICAgIGFyclt4XVt5XT0nWCc7Cn0Kdm9pZCBzb2x2ZSgpIAp7CiAgICBtZW1zZXQodmlzLCAwLCBzaXplb2YodmlzKSk7CiAgICBtZW1zZXQoY29tcCwwLHNpemVvZihjb21wKSk7CiAgICBtZW1zZXQocHFyLDAsc2l6ZW9mKHBxcikpOwogICAgbiA9IEEuc2l6ZSgpOwogICAgbSA9IEFbMF0uc2l6ZSgpOwogICAgaW50IGlkPTE7CiAgICBmb3IoaW50IGk9MDtpPG47aSsrKQogICAgICAgIGZvciAoaW50IGo9MDtqPG07aisrKQogICAgICAgIHsKICAgICAgICAgICAgaWYoY2hlY2soaSxqKSkKICAgICAgICAgICAge2RmcyhpLGosaWQpOwogICAgICAgICAgICBpZCsrO30KICAgICAgICB9CiAgICBmb3IoaW50IGk9MDtpPG47aSsrKQogICAgewogICAgICAgIGlmKGk9PTB8fGk9PW4tMSkKICAgICAgICB7CiAgICAgICAgICAgIGZvcihpbnQgaj0wO2o8bTtqKyspCiAgICAgICAgICAgICAgICBwcXJbY29tcFtpXVtqXV09MTsKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAgICAgcHFyW2NvbXBbaV1bMF1dPTE7CiAgICAgICAgICAgIHBxcltjb21wW2ldW20tMV1dPTE7CiAgICAgICAgfQogICAgfQogICAgZm9yKGludCBpPTA7aTxuO2krKykKICAgICAgICBmb3IgKGludCBqPTA7ajxtO2orKykKICAgICAgICB7CiAgICAgICAgICAgIGZsaXAoaSxqKTsKICAgICAgICB9Cn0K
compilation info
prog.cpp:6:1: error: 'vector' does not name a type
vector<vector<char>>arr;
^
prog.cpp: In function 'bool check(int, int)':
prog.cpp:9:30: error: 'arr' was not declared in this scope
if(x>=0&&x<n&&y>=0&&y<m&&arr[x][y]=='O'&&!vis[x][y])
^
prog.cpp: In function 'void flip(int, int)':
prog.cpp:31:9: error: 'arr' was not declared in this scope
arr[x][y]='X';
^
prog.cpp: In function 'void solve()':
prog.cpp:35:31: error: 'memset' was not declared in this scope
memset(vis, 0, sizeof(vis));
^
prog.cpp:38:9: error: 'A' was not declared in this scope
n = A.size();
^
stdout