Submission #1187782

#TimeUsernameProblemLanguageResultExecution timeMemory
1187782M_W_13Bitaro the Brave (JOI19_ho_t1)C++20
100 / 100
120 ms79772 KiB
#include <bits/stdc++.h>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
#define pb push_back
#define st first
#define nd second

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, m;
    cin >> n >> m;
    char T[n][m];
    rep(i, n) {
        string s;
        cin >> s;
        rep(j, m) {
            T[i][j] = s[j];
        }
    }
    int ile[n + 1][m + 1][2];
    rep(i, n + 1) {
        rep(j, m + 1) {
            rep(c, 2) {
                ile[i][j][c] = 0;
            }
        }
    }
    for (int i = n - 1; i >= 0; i--) {
        for (int j = m - 1; j >= 0; j--) {
            ile[i][j][0] = ile[i][j + 1][0];
            if (T[i][j] == 'O') {
                ile[i][j][0]++;
            }
            ile[i][j][1] = ile[i + 1][j][1];
            if (T[i][j] == 'I') {
                ile[i][j][1]++;
            }
        }
    }
    ll ans = 0;
    rep(i, n) {
        rep(j, m) {
            if (T[i][j] == 'J' && (i + 1 < n) && (j + 1 < m)) {
                ans += (((long long)ile[i][j + 1][0]) * ((long long)ile[i + 1][j][1]));
            }
        }
    }
    cout << ans << '\n';
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...