#include<bits/stdc++.h>
#define fo(x, y, z) for(int (x) = (y); (x) <= (z); (x)++)
#define fu(x, y, z) for(int (x) = (y); (x) >= (z); (x)--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define lx ll
inline lx qr()
{
char ch = getchar_unlocked(); lx x = 0, f = 1;
for(; ch < '0' || ch > '9'; ch = getchar_unlocked()) if(ch == '-') f = -1;
for(; ch >= '0' && ch <= '9'; ch = getchar_unlocked()) x = (x << 3) + (x << 1) + (ch ^ 48);
return x * f;
}
#undef lx
#define qr qr()
#define pii pair<int, int>
#define fi first
#define se second
#define M_P(x, y) make_pair(x, y)
#define P_B(x) push_back(x)
const int Ratio = 0;
const int N = 200 + 5;
const int mod = 1e9 + 7;
int n;
int d[N][N], ans[4][N];
namespace Wisadel
{
void Wdfs(int x, int y, int now, int nc)
{
if(x == nc && y < 2 * n - nc)
{
if(now == 1 && d[x][y + 1] == 0)
{
if(y <= n)
{
ans[1][nc] = n - y;
fo(i, 2, 4) ans[i][nc] = ans[i - 1][nc] + 2 * (n - nc + 1) - 1;
}
else
{
ans[2][nc] = 2 * n - nc - y + (n - nc + 1) - 1;
fo(i, 3, 4) ans[i][nc] = ans[i - 1][nc] + 2 * (n - nc + 1) - 1;
ans[1][nc] = ans[4][nc] + 2 * (n - nc + 1) - 1;
}
return ;
}
Wdfs(x, y + 1, d[x][y + 1], nc);
return ;
}
if(x == nc && y == 2 * n - nc)
{
if(now == 1 && d[x + 1][y] == 0)
{
ans[2][nc] = (n - nc + 1) - 1;
fo(i, 3, 4) ans[i][nc] = ans[i - 1][nc] + 2 * (n - nc + 1) - 1;
ans[1][nc] = ans[4][nc] + 2 * (n - nc + 1) - 1;
return ;
}
Wdfs(x + 1, y, d[x + 1][y], nc);
return ;
}
if(y == 2 * n - nc && x < 2 * n - nc)
{
if(now == 1 && d[x + 1][y] == 0)
{
if(x <= n)
{
ans[2][nc] = n - x;
fo(i, 3, 4) ans[i][nc] = ans[i - 1][nc] + 2 * (n - nc + 1) - 1;
ans[1][nc] = ans[4][nc] + 2 * (n - nc + 1) - 1;
}
else
{
ans[3][nc] = 2 * n - nc - x + (n - nc + 1) - 1;
ans[4][nc] = ans[3][nc] + 2 * (n - nc + 1) - 1;
ans[1][nc] = ans[4][nc] + 2 * (n - nc + 1) - 1;
ans[2][nc] = ans[1][nc] + 2 * (n - nc + 1) - 1;
}
return ;
}
Wdfs(x + 1, y, d[x + 1][y], nc);
return ;
}
if(y == 2 * n - nc && x == 2 * n - nc)
{
if(now == 1 && d[x][y - 1] == 0)
{
ans[3][nc] = (n - nc + 1) - 1;
ans[4][nc] = ans[3][nc] + 2 * (n - nc + 1) - 1;
ans[1][nc] = ans[4][nc] + 2 * (n - nc + 1) - 1;
ans[2][nc] = ans[1][nc] + 2 * (n - nc + 1) - 1;
return ;
}
Wdfs(x, y - 1, d[x][y - 1], nc);
return ;
}
if(x == 2 * n - nc && y > nc)
{
if(now == 1 && d[x][y - 1] == 0)
{
if(y > n)
{
ans[3][nc] = y - n - 1;
ans[4][nc] = ans[3][nc] + 2 * (n - nc + 1) - 1;
ans[1][nc] = ans[4][nc] + 2 * (n - nc + 1) - 1;
ans[2][nc] = ans[1][nc] + 2 * (n - nc + 1) - 1;
}
else
{
ans[4][nc] = y - nc - 1 + (n - nc + 1) - 1;
ans[1][nc] = ans[4][nc] + 2 * (n - nc + 1) - 1;
fo(i, 2, 3) ans[i][nc] = ans[i - 1][nc] + 2 * (n - nc + 1) - 1;
}
return ;
}
Wdfs(x, y - 1, d[x][y - 1], nc);
return ;
}
if(x == 2 * n - nc && y == nc)
{
if(now == 1 && d[x - 1][y] == 0)
{
ans[4][nc] = (n - nc + 1) - 1;
ans[1][nc] = ans[4][nc] + 2 * (n - nc + 1) - 1;
fo(i, 2, 3) ans[i][nc] = ans[i - 1][nc] + 2 * (n - nc + 1) - 1;
return ;
}
Wdfs(x - 1, y, d[x - 1][y], nc);
return ;
}
if(x > nc && y == nc)
{
if(now == 1 && d[x - 1][y] == 0)
{
if(x > n)
{
ans[4][nc] = x - n - 1;
ans[1][nc] = ans[4][nc] + 2 * (n - nc + 1) - 1;
fo(i, 2, 3) ans[i][nc] = ans[i - 1][nc] + 2 * (n - nc + 1) - 1;
}
else
{
ans[1][nc] = x - nc - 1 + (n - nc + 1) - 1;
fo(i, 2, 4) ans[i][nc] = ans[i - 1][nc] + 2 * (n - nc + 1) - 1;
}
return ;
}
Wdfs(x - 1, y, d[x - 1][y], nc);
return ;
}
}
short main()
{
// freopen(".in", "r", stdin), freopen(".out", "w", stdout);
n = qr;
fo(i, 1, 2 * n) fo(j, 1, 2 * n)
{
char ch;
cin >> ch;
d[i][j] = (ch == 'X');
}
fo(i, 1, n)
Wdfs(i, i, d[i][i], i);
int anss = 1e9;
fo(i, 1, 4)
{
int res = 0;
fo(j, 1, n) res += ans[i][j];
anss = min(anss, res);
}
printf("%d\n", anss);
return Ratio;
}
}
signed main(){return Wisadel::main();}
// 佳墙坂诶迦币等渔塞
标签:ch,return,22,int,nc,ans,fo
From: https://www.cnblogs.com/Ratio-Yinyue1007/p/18535866