Submission #541534

#TimeUsernameProblemLanguageResultExecution timeMemory
541534happypotatoBitaro the Brave (JOI19_ho_t1)C++17
100 / 100
262 ms89384 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void init() {

}
void solve() {
    int h, w;
    cin >> h >> w;
    string a[h];
    for (int i = 0; i < h; i++) cin >> a[i];
    int psi[h][w], pso[h][w];
    for (int i = 0; i < w; i++) {
        psi[h - 1][i] = 0;
        for (int j = h - 2; j >= 0; j--) {
            psi[j][i] = psi[j + 1][i] + (a[j + 1][i] == 'I');
        }
    }
    for (int i = 0; i < h; i++) {
        pso[i][w - 1] = 0;
        for (int j = w - 2; j >= 0; j--) {
            pso[i][j] = pso[i][j + 1] + (a[i][j + 1] == 'O');
        }
    }
    ll int ans = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (a[i][j] == 'J') {
                ans += psi[i][j] * pso[i][j];
            }
        }
    }
    cout << ans << endl;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    init();
    solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...