int cnt = 0; std::vector<int> last; for (int i = 1; i <= 4; i++) { if (part[i] != 0) last.push_back(i); } if (last.size() == 2) { ans += std::min(part[last[0]], part[last[1]]); }
/******************************************************** > File Name: f.cpp > Author: zylll > Blog: https://ylzhang.top > Created Time: Mon Oct 27 23:10:47 2025 *******************************************************/
#include<bits/stdc++.h>
constint MAXN = 105; constint ASCII_SIZE = 200; int n, m; std::vector<std::string> a, b;
int vnum[ASCII_SIZE][MAXN], hnum[ASCII_SIZE][MAXN];
boolcheck_v(char c){ for (int i = 1; i <= n; i++) { if (vnum[c][i] < 4) continue; for (int j = 1; j + 3 <= m; j++) { if (a[i][j] == c && a[i][j + 1] == c && a[i][j + 2] == c && a[i][j + 3] == c) { return1; } } } return0; }
boolcheck_h(char c){ for (int j = 1; j <= m; j++) { if (hnum[c][j] < 4) continue; for (int i = 0; i + 3 < n; i++) { if (b[j][i] == c && b[j][i + 1] == c && b[j][i + 2] == c && b[j][i + 3] == c) { return1; } } } return0; }
boolcheck_vh(char c){ int delx = 1, dely = 1; for (int j = 1; j <= m; j++) { int sx = 1, sy = j, cnt = 0;
while (sx <= n && sy <= m) { if (a[sx][sy] == c) cnt++; else cnt = 0; sx += delx; sy += dely;
if (cnt == 4) return1; } }
for (int i = 2; i <= n; i++) { int sx = i, sy = 1, cnt = 0; while (sx <= n && sy <= m) { if (a[sx][sy] == c) cnt++; else cnt = 0; sx += delx; sy += dely;
if (cnt == 4) return1; } }
dely = -1; for (int j = 1; j <= m; j++) { int sx = 1, sy = j, cnt = 0; while (sx <= n && sy > 0) { if (a[sx][sy] == c) cnt++; else cnt = 0; sx += delx; sy += dely;
if (cnt == 4) return1; } }
for (int i = 2; i <= n; i++) { int sx = i, sy = m, cnt = 0; while (sx <= n && sy > 0) { if (a[sx][sy] == c) cnt++; else cnt = 0; sx += delx; sy += dely;