Submission #1275368

#TimeUsernameProblemLanguageResultExecution timeMemory
1275368MisterReaperBitaro the Brave (JOI19_ho_t1)C++20
100 / 100
248 ms151436 KiB
// File bravebitaro.cpp created on 02.10.2025 at 10:59:28
#include <bits/stdc++.h>

using i64 = long long;

#ifdef DEBUG 
    #include "/home/ahmetalp/Desktop/Workplace/debug.h"
#else
    #define debug(...) void(23)
#endif

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int N, M;
    std::cin >> N >> M;

    std::vector<std::string> A(N);
    for (int i = 0; i < N; ++i) {
        std::cin >> A[i];
    }

    std::vector<std::vector<i64>> f(N + 1, std::vector<i64>(M));
    std::vector<std::vector<i64>> g(N, std::vector<i64>(M + 1));
    for (int i = N - 1; i >= 0; --i) {
        for (int j = 0; j < M; ++j) {
            f[i][j] = f[i + 1][j] + (A[i][j] == 'I');
        }
    }
    for (int j = M - 1; j >= 0; --j) {
        for (int i = 0; i < N; ++i) {
            g[i][j] = g[i][j + 1] + (A[i][j] == 'O');
        }
    }

    i64 ans = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            if (A[i][j] == 'J') {
                ans += f[i][j] * g[i][j];
            }
        }
    }

    std::cout << ans << '\n';

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...