正文
增加 18 行删除 18 行
47 行未改动4849505152535455564 行未改动6162636465666768697071727374757677787980818283848512 行未改动98991001011021031041051061071081091101111121131141153 行未改动1191201211221231241251261275 行未改动13313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119247 行未改动mat[ row ][ i ] = tmp[ i ];for( int i = 0; i < ( int )koord.size(); ++i )if( koord[ i ].Row == row )koord[ i ].Col = ( koord[ i ].Col + K ) % S;sprintf( tmpbuff, "rotR %d %d", row + 1, K );rez.push_back( string( tmpbuff ) );}4 行未改动mat[ i ][ col ] = tmp[ i ];for( int i = 0; i < ( int )koord.size(); ++i )if( koord[ i ].Col == col )koord[ i ].Row = ( koord[ i ].Row + K ) % R;sprintf( tmpbuff, "rotS %d %d", col + 1, K );rez.push_back( string( tmpbuff ) );}void changerow( int row ) {for( int i = 0; i < S; ++i )mat[ row ][ i ] = -mat[ row ][ i ];sprintf( tmpbuff, "negR %d", row + 1 );rez.push_back( string( tmpbuff ) );}void changecol( int col ) {for( int i = 0; i < R; ++i )mat[ i ][ col ] = -mat[ i ][ col ];sprintf( tmpbuff, "negS %d", col + 1 );rez.push_back( string( tmpbuff ) );}12 行未改动if( !ozn[ i ][ j ] && mat[ i ][ j ] == X ) {ozn[ i ][ j ] = 1;return make_pair( i, j );}return make_pair( -1, -1 );}void sredi_stupac( void ) {int len = ( int )koord.size();for( int i = 0; i < len; ++i ) {int razl = i - koord[ i ].Row;if( razl < 0 ) razl += R;if( koord[ i ].Col == 0 ) rotaterow( koord[ i ].Row, 1 );if( koord[ i ].Row != i ) rotatecol( koord[ i ].Col, razl );rotaterow( koord[ i ].Row, S - koord[ i ].Col );}3 行未改动int len = ( int )koord.size();for( int i = 0; i < len; ++i ) {int razl = i - koord[ i ].Col;if( razl < 0 ) razl += S;if( koord[ i ].Row == 0 ) rotatecol( koord[ i ].Col, 1 );if( koord[ i ].Col != i ) rotaterow( koord[ i ].Row, razl );rotatecol( koord[ i ].Col, R - koord[ i ].Row );}5 行未改动for( int j = 0; j < S; ++j ) {scanf( "%d", &mat[ i ][ j ] );niz[ S * i + j ] = mat[ i ][ j ];}sort( niz, niz + R * S );for( int i = 0; i < R * S; ++i ) {negativnih += ( niz[ i ] < 0 );sumuk[ i ] = ( i > 0 ? sumuk[ i-1 ] : 0 ) + niz[ i ];if( !moguce[ i ] ) continue;moguce[ i + R ] = 1;moguce[ i + S ] = 1;recon[ i + R ] = i;recon[ i + S ] = i;}int X, A = -1, B = -1;for( int i = 0; i <= R * S; ++i ) {if( !moguce[ i ] ) continue;if( i <= negativnih ) A = i;if( i >= negativnih && B == -1 )B = i;}if( A == -1 ) X = B; else if( B == -1 ) X = A;else X = ( evalpod( A ) > evalpod( B ) ? A : B );int prez = evalpod( X );while( X != 0 ) {por[ cnt++ ] = X;X = recon[ X ];}por[ cnt++ ] = 0;reverse( por, por + cnt );for( int i = 0; i < cnt-1; ++i ) {memset( ozn, 0, sizeof( ozn ) );koord.clear();for( int j = por[ i ]; j < por[ i + 1 ]; ++j )koord.push_back( pronadji( niz[ j ] ) );if( por[ i + 1 ] - por[ i ] == R ) {sredi_stupac();changecol( 0 );} else {sredi_redak();changerow( 0 );}}printf( "%d %d\n", prez, ( int )rez.size() );for( int i = 0; i < ( int )rez.size(); ++i )printf( "%s\n", rez[ i ].c_str() );return( 0 );}```47 行未改动4849505152535455564 行未改动6162636465666768697071727374757677787980818283848512 行未改动98991001011021031041051061071081091101111121131141153 行未改动1191201211221231241251261275 行未改动13313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119247 行未改动mat[ row ][ i ] = tmp[ i ];for( int i = 0; i < ( int )koord.size(); ++i )if( koord[ i ].Row == row )koord[ i ].Col = ( koord[ i ].Col + K ) % S;sprintf( tmpbuff, "rotR %d %d", row + 1, K );rez.push_back( string( tmpbuff ) );}4 行未改动mat[ i ][ col ] = tmp[ i ];for( int i = 0; i < ( int )koord.size(); ++i )if( koord[ i ].Col == col )koord[ i ].Row = ( koord[ i ].Row + K ) % R;sprintf( tmpbuff, "rotS %d %d", col + 1, K );rez.push_back( string( tmpbuff ) );}void changerow( int row ) {for( int i = 0; i < S; ++i )mat[ row ][ i ] = -mat[ row ][ i ];sprintf( tmpbuff, "negR %d", row + 1 );rez.push_back( string( tmpbuff ) );}void changecol( int col ) {for( int i = 0; i < R; ++i )mat[ i ][ col ] = -mat[ i ][ col ];sprintf( tmpbuff, "negS %d", col + 1 );rez.push_back( string( tmpbuff ) );}12 行未改动if( !ozn[ i ][ j ] && mat[ i ][ j ] == X ) {ozn[ i ][ j ] = 1;return make_pair( i, j );}return make_pair( -1, -1 );}void sredi_stupac( void ) {int len = ( int )koord.size();for( int i = 0; i < len; ++i ) {int razl = i - koord[ i ].Row;if( razl < 0 ) razl += R;if( koord[ i ].Col == 0 ) rotaterow( koord[ i ].Row, 1 );if( koord[ i ].Row != i ) rotatecol( koord[ i ].Col, razl );rotaterow( koord[ i ].Row, S - koord[ i ].Col );}3 行未改动int len = ( int )koord.size();for( int i = 0; i < len; ++i ) {int razl = i - koord[ i ].Col;if( razl < 0 ) razl += S;if( koord[ i ].Row == 0 ) rotatecol( koord[ i ].Col, 1 );if( koord[ i ].Col != i ) rotaterow( koord[ i ].Row, razl );rotatecol( koord[ i ].Col, R - koord[ i ].Row );}5 行未改动for( int j = 0; j < S; ++j ) {scanf( "%d", &mat[ i ][ j ] );niz[ S * i + j ] = mat[ i ][ j ];}sort( niz, niz + R * S );for( int i = 0; i < R * S; ++i ) {negativnih += ( niz[ i ] < 0 );sumuk[ i ] = ( i > 0 ? sumuk[ i-1 ] : 0 ) + niz[ i ];if( !moguce[ i ] ) continue;moguce[ i + R ] = 1;moguce[ i + S ] = 1;recon[ i + R ] = i;recon[ i + S ] = i;}int X, A = -1, B = -1;for( int i = 0; i <= R * S; ++i ) {if( !moguce[ i ] ) continue;if( i <= negativnih ) A = i;if( i >= negativnih && B == -1 )B = i;}if( A == -1 ) X = B; else if( B == -1 ) X = A;else X = ( evalpod( A ) > evalpod( B ) ? A : B );int prez = evalpod( X );while( X != 0 ) {por[ cnt++ ] = X;X = recon[ X ];}por[ cnt++ ] = 0;reverse( por, por + cnt );for( int i = 0; i < cnt-1; ++i ) {memset( ozn, 0, sizeof( ozn ) );koord.clear();for( int j = por[ i ]; j < por[ i + 1 ]; ++j )koord.push_back( pronadji( niz[ j ] ) );if( por[ i + 1 ] - por[ i ] == R ) {sredi_stupac();changecol( 0 );} else {sredi_redak();changerow( 0 );}}printf( "%d %d\n", prez, ( int )rez.size() );for( int i = 0; i < ( int )rez.size(); ++i )printf( "%s\n", rez[ i ].c_str() );return( 0 );}```