From ccd6b3afe0f131cc7d4719dce447eed54d18b3cd Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Fri, 21 Oct 2022 14:34:57 +0800 Subject: [PATCH] L - Leverage MDT https://codeforces.com/gym/102428/submission/177267446 --- Gym/102428/L/L.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Gym/102428/L/L.cpp diff --git a/Gym/102428/L/L.cpp b/Gym/102428/L/L.cpp new file mode 100644 index 00000000..60ad6d0d --- /dev/null +++ b/Gym/102428/L/L.cpp @@ -0,0 +1,58 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1005; + +int n, m, f[N][N], ans; +bool g[N][N]; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + char c; + + cin >> c; + + g[i][j] = c == 'G'; + f[i][j] = g[i][j] == g[i][j - 1] ? f[i][j - 1] + 1 : 1; + } + } + + for (int p = 1; p <= m; p++) { + std::stack> st; + + for (int i = 1; i <= n; i++) { + int l = 0; + + while (!st.empty() && f[st.top().first][p] >= f[i][p]) { + l += st.top().second; + ans = std::max(ans, std::min(f[st.top().first][p], l)); + st.pop(); + } + + st.emplace(i, l + 1); + } + + int l = 0; + + while (!st.empty()) { + l += st.top().second; + ans = std::max(ans, std::min(f[st.top().first][p], l)); + st.pop(); + } + } + + cout << ans * ans << endl; + + return 0; +}