Submission #947219

#TimeUsernameProblemLanguageResultExecution timeMemory
947219devkudawlaBitaro the Brave (JOI19_ho_t1)C++17
100 / 100
355 ms89496 KiB
#include <bits/stdc++.h>
using namespace std;
void solve(bool testCases = true) {
    int T = 1;
    if (testCases) cin >> T;
    while (T--) {
        int n, m;
        cin >> n >> m;
        vector<string> v(n);
        for (int i = 0; i < n; i++) {
            cin >> v[i];
        }
        int r[n][m] = {0};
        memset(r, 0, sizeof(r));
        for (int i = 0; i < n; i++) {
            for (int j = m - 2; j >= 0; j--) {
                r[i][j] += r[i][j + 1];
                if (v[i][j + 1] == 'O') {
                    r[i][j]++;
                }
            }
        }
        int c[n][m] = {0};
        memset(c, 0, sizeof(c));
        for (int j = 0; j < m; j++) {
            for (int i = n - 2; i >= 0; i--) {
                c[i][j] += c[i + 1][j];
                if (v[i + 1][j] == 'I') {
                    c[i][j]++;
                }
            }
        }
        long long int answer = 0;
        for (int j = 0; j < m; j++) {
            for (int i = 0; i < n; i++) {
                if (v[i][j] == 'J') {
                    answer += (r[i][j] * 1LL * c[i][j]);
                }
            }
        }
        cout << answer;
        cout << "\n";
    }
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve(false);
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...