problem analysis
It is contemplated that first, the position coordinates and an odd number can be uniquely determined. Similarly, if it is assumed \ ((1,2) \) is \ (0 \) , then the coordinate is an even number and position may also be determined uniquely. Such uses a total of \ (n ^ 2-3 \) once asked.
Then the next need in \ (3 \) within determines whether to flip steps coordinate is an even number and location.
If just this simple judgment:
printf( "? 1 1 2 3\n" ); fflush( stdout );
int x; scanf( "%d", &x );
if( x == 1 && A[ 1 ][ 1 ] != A[ 2 ][ 3 ] )
for( int i = 1; i <= n; ++i )
for( int j = 1; j <= n; ++j )
if( ( i + j ) % 2 )
A[ i ][ j ] = ( A[ i ][ j ] == 1 ) ? 0 : 1;
if( x == 0 && A[ 1 ][ 1 ] == A[ 2 ][ 3 ] &&
( A[ 2 ][ 1 ] == A[ 2 ][ 2 ] || A[ 1 ][ 2 ] == A[ 2 ][ 2 ] || A[ 1 ][ 2 ] == A[ 1 ][ 3 ] ) )
for( int i = 1; i <= n; ++i )
for( int j = 1; j <= n; ++ j )
if( ( i + j ) % 2 )
A[ i ][ j ] = ( A[ i ][ j ] == 1 ) ? 0 : 1;
Then pleasant Wrong Answer on test 5
.
Such a set of data was observed:
110
101
110
Will find that, whether or not flip, are the results obtained \ (0 \) .
Observed that such a change would flip length \ (4 \) two positions on the path. And the exclusive OR values on such path is constant. And a length of \ (4 \) a \ (01 \) string and to the exclusive OR \ (0 \) is a necessary condition palindromic. If not, and the exclusive OR \ (0 \) , to the inverse situation will appear in the embodiment.
And then XOR is \ (0 \) length of \ (4 \) whether the path must exist? Consider reductio ad absurdum.
Suppose such a path does not exist. From top left to bottom right to consider any path. Length of this path is \ (. 1-2N \) . We may assume that this path is composed of a sequence \ (\ {a_i \} \) . So \ (A_1 \ oplus A_2 \ oplus A_3 \ oplus A_4 = 1 \) , \ (A_2 \ oplus A_3 \ oplus A_4 \ oplus A_5 = 1 \) . So \ (A_1 = A_5 \) . The same \ (= a_i. 4-A_ {I} \) . Because of \ (n-\) is an odd number, so \ (A_. 1} = {2N-A_1 \) . The title claim \ (A_1 =. 1, 2N-A_. 1} = {0 \) , so there is a certain path.
Then get a feasible approach.
Reference program
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 60;
int n, A[ Maxn ][ Maxn ], x;
int Check( int x1, int y1, int x2, int y2 ) {
if( x1 == x2 ) return 1 ^ A[ x1 ][ y1 ] ^ A[ x1 ][ y1 + 1 ] ^ A[ x1 ][ y1 + 2 ] ^ A[ x1 ][ y2 ];
if( x1 + 1 == x2 ) {
int t = A[ x1 ][ y1 ] ^ A[ x2 ][ y2 ];
return ( t == ( A[ x1 + 1 ][ y1 ] ^ A[ x1 + 1 ][ y1 + 1 ] ) ) ||
( t == ( A[ x1 ][ y1 + 1 ] ^ A[ x1 + 1 ][ y1 + 1 ] ) ) ||
( t == ( A[ x1 ][ y1 + 1 ] ^ A[ x1 ][ y1 + 2 ] ) );
}
if( x1 + 2 == x2 ) {
int t = A[ x1 ][ y1 ] ^ A[ x2 ][ y2 ];
return ( t == ( A[ x1 + 1 ][ y1 ] ^ A[ x1 + 2 ][ y1 ] ) ) ||
( t == ( A[ x1 + 1 ][ y1 ] ^ A[ x1 + 1 ][ y1 + 1 ] ) ) ||
( t == ( A[ x1 ][ y1 + 1 ] ^ A[ x1 + 1 ][ y1 + 1 ] ) );
}
if( x1 + 3 == x2 ) return 1 ^ A[ x1 ][ y1 ] ^ A[ x1 + 1 ][ y1 ] ^ A[ x1 + 2 ][ y1 ] ^ A[ x2 ][ y1 ];
return 0;
}
void Swap() {
for( int i = 1; i <= n; ++i )
for( int j = 1; j <= n; ++j )
if( ( i + j ) % 2 )
A[ i ][ j ] = ( A[ i ][ j ] == 1 ) ? 0 : 1;
return;
}
void Trans() {
for( int i = 1; i <= n; ++i )
for( int j = 1; j <= n; ++j )
for( int k = 0; k < 4; ++k )
if( i + k <= n && j + 3 - k <= n && Check( i, j, i + k, j + 3 - k ) ) {
printf( "? %d %d %d %d\n", i, j, i + k, j + 3 - k ); fflush( stdout ); scanf( "%d", &x );
if( x == 1 && A[ i ][ j ] != A[ i + k ][ j + 3 - k ] ) Swap();
if( x == 0 && A[ i ][ j ] == A[ i + k ][ j + 3 - k ] ) Swap();
return;
}
return;
}
int main() {
memset( A, 0, sizeof( A ) );
A[ 1 ][ 1 ] = 1;
scanf( "%d", &n );
for( int i = 1; i <= n; ++i )
for( int j = 1; j <= n; ++j ) {
if( i == 2 && j == 1 ) {
printf( "? 2 1 2 3\n" ); fflush( stdout ); scanf( "%d", &x );
if( x == 0 ) A[ 2 ][ 1 ] = ( A[ 2 ][ 3 ] == 1 ) ? 0 : 1;
if( x == 1 ) A[ 2 ][ 1 ] = ( A[ 2 ][ 3 ] == 1 ) ? 1 : 0;
}
if( i == 1 && j + 2 <= n ) {
printf( "? %d %d %d %d\n", i, j, i, j + 2 ); fflush( stdout ); scanf( "%d", &x );
if( x == 0 ) A[ i ][ j + 2 ] = ( A[ i ][ j ] == 1 ) ? 0 : 1;
if( x == 1 ) A[ i ][ j + 2 ] = ( A[ i ][ j ] == 1 ) ? 1 : 0;
}
if( j == 1 && i + 2 <= n ) {
printf( "? %d %d %d %d\n", i, j, i + 2, j ); fflush( stdout ); scanf( "%d", &x );
if( x == 0 ) A[ i + 2 ][ j ] = ( A[ i ][ j ] == 1 ) ? 0 : 1;
if( x == 1 ) A[ i + 2 ][ j ] = ( A[ i ][ j ] == 1 ) ? 1 : 0;
}
if( i + 1 <= n && j + 1 <= n && i + j + 2 < n + n ) {
printf( "? %d %d %d %d\n", i, j, i + 1, j + 1 ); fflush( stdout ); scanf( "%d", &x );
if( x == 0 ) A[ i + 1 ][ j + 1 ] = ( A[ i ][ j ] == 1 ) ? 0 : 1;
if( x == 1 ) A[ i + 1 ][ j + 1 ] = ( A[ i ][ j ] == 1 ) ? 1 : 0;
}
}
Trans();
printf( "!\n" ); fflush( stdout );
for( int i = 1; i <= n; ++i ) {
for( int j = 1; j <= n; ++j )
printf( "%d", A[ i ][ j ] ), fflush( stdout );
printf( "\n" ); fflush( stdout );
}
return 0;
}