#include <bits/stdc++.h> #define f64 intfast64t #define optimize()…
- User
#include <bits/stdc++.h> #define f64 int_fast64_t #define optimize() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define io(s) if (fopen(s".inp", "r")) {freopen(s".inp", "r", stdin); freopen(s".out", "w", stdout);}; #define endl '\n' #define all(p) p.begin(), p.end() #define MOD 1000000007 #pragma GCC optimize("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2") using namespace std;
const f64 MAX = 2000; char board[MAX][MAX]; f64 sumA[MAX][MAX]; f64 m, n, k;
inline f64 countA(f64 x1, f64 y1, f64 x2, f64 y2) { return sumA[x2][y2] - sumA[x1 - 1][y2] - sumA[x2][y1 - 1] + sumA[x1 - 1][y1 - 1]; }
inline bool isBeautiful(f64 x1, f64 y1, f64 x2, f64 y2) { f64 area = (x2 - x1 + 1) * (y2 - y1 + 1); f64 numA = countA(x1, y1, x2, y2); f64 numB = area - numA; return abs(numA - numB) <= k; }
int main() { optimize(); io(""); f64 t; cin >> t; while (t--) { cin >> m >> n >> k; for (f64 i = 1; i <= m; i++) { for (f64 j = 1; j <= n; j++) { cin >> board[i][j]; sumA[i][j] = sumA[i - 1][j] + sumA[i][j - 1] - sumA[i - 1][j - 1] + (board[i][j] == 'A'); } } f64 ans = 0; for (f64 x1 = 1; x1 <= m; x1++) for (f64 y1 = 1; y1 <= n; y1++) for (f64 x2 = x1; x2 <= m; x2++) for (f64 y2 = y1; y2 <= n; y2++) if (isBeautiful(x1, y1, x2, y2)) ans = max(ans, (x2 - x1 + 1) * (y2 - y1 + 1)); cout << ans << '\n'; } return 0; } áp dụng thuật toán kadane cho mảng 2 chiều vào code này
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.