제출 #1268318

#제출 시각아이디문제언어결과실행 시간메모리
1268318recpBitaro the Brave (JOI19_ho_t1)C++20
100 / 100
170 ms151460 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second

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

    int h, w;
    cin >> h >> w;
    string arr[h];
    for (int i = 0; i < h; i++) cin >> arr[i];
    vector<vector<ll>> prefO(h+1, vector<ll>(w+1, 0));
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            prefO[i][j] = prefO[i][j-1]+(arr[i-1][j-1] == 'O');
        }
    }
    vector<vector<ll>> prefI(w+1, vector<ll>(h+1, 0));
    for (int i = 1; i <= w; i++) {
        for (int j = 1; j <= h; j++) {
            prefI[i][j] = prefI[i][j-1]+(arr[j-1][i-1] == 'I');
        }
    }
    ll ans = 0;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (arr[i-1][j-1] == 'J') {
                ans += (prefO[i][w]-prefO[i][j])*(prefI[j][h]-prefI[j][i]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...