PLDIS @ 2025-01-11 13:47:25
RT,洛谷 100pts,但是没有任何正确性。
#include <iostream>
#include <cstring>
#define int long long
using namespace std;
void init_vars();
void solve(int testcase, ...);
signed main(){
#ifdef files
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
solve(1);
#ifdef files
fclose(stdin); fclose(stdout);
#endif
return 0;
}
int dp[5000024], val[10][10];
char s[10][10];
int calc(int x, int y){
if(x <= 3 && y <= 3) return (1 << 18);
if(x <= 3 && y <= 6) return (1 << 19);
if(x <= 6 && y <= 3) return (1 << 20);
if(x <= 6 && y <= 6) return (1 << 21);
return 0;
}
void init_vars(){
memset(dp, 0x3f3f3f3f, sizeof(dp));
for(int i = 1; i <= 9; i++){
for(int j = 1; j <= 9; j++)
val[i][j] = (1 << (i - 1)) + (1 << (8 + j)) + calc(i, j);
}
}
int min(int x, int y){
if(x < y) return x;
return y;
}
void solve(int testcase, ...){
init_vars();
for(int i = 1; i <= 9; i++)
scanf("%s", s[i]);
int curr = 0;
for(int i = 1; i <= 9; i++){
for(int j = 1; j <= 9; j++){
if(s[i][j - 1] == '1'){
curr ^= (1 << (i - 1)) + (1 << (8 + j)) + calc(i, j);
}
}
}
dp[0] = 0;
for(int i = 0; i < (1 << 22); i++){
if(dp[i] != dp[5000023])
for(int x = 1; x <= 9; x++)
for(int y = 1; y <= 9; y++)
dp[i ^ val[x][y]] = min(dp[i] + 1, dp[i ^ val[x][y]]);
}
for(int i = (1 << 22) - 1; i >= 1; i--)
if(dp[i] != dp[5000023])
for(int x = 1; x <= 9; x++)
for(int y = 1; y <= 9; y++)
dp[i ^ val[x][y]] = min(dp[i] + 1, dp[i ^ val[x][y]]);
printf("%lld\n", dp[curr]);
}
/*
* things to check
* 1. CZY's brain
* 2. ...
**/
/*
* something to think about
* 1. how to fix my brain?
**/
/*
########## ############ ##### #####
#### ##### #### ####
#### ##### #### ####
#### ########## #### ####
#### ##### #####
#### ##### #####
#### ##### #####
########### ############# #####
*/