제출 #1332433

#제출 시각아이디문제언어결과실행 시간메모리
1332433lywoemBitaro the Brave (JOI19_ho_t1)C++20
100 / 100
285 ms150624 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define l(a, b, i) for (ll i = a; i < b; i++)
#define rl(a, b, i) for (ll i = a; i >= b; i--)
#define vpair vector<pair<ll, ll>>
#define inf LLONG_MAX
#define ninf LLONG_MIN

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll H, W; cin >> H >> W; vector<vector<char>> grid(H + 1, vector<char> (W + 1));
    l(1, H + 1, r) {
        string s; cin >> s;
        l(1, W + 1, c) grid[r][c] = s[c - 1]; // c - 1 vi string la 0-indexed a :)
    }

    vector<vector<ll>> preI(H + 1, vector<ll> (W + 1, 0)); 
    // preI[r][c] = no. of I in column c, up till row r 
    vector<vector<ll>> preO(H + 1, vector<ll> (W + 1, 0));
    // preO[r][c] = no. of O in row r, up till column c

    l(1, W + 1, c) { // preI
        l(1, H + 1, r) {
            preI[r][c] = preI[r - 1][c];
            if (grid[r][c] == 'I') preI[r][c]++;
        }
    }

    l(1, H + 1, r) { // preO
        l(1, W + 1, c) {
            preO[r][c] = preO[r][c - 1];
            if (grid[r][c] == 'O') preO[r][c]++;
        }
    }

    ll ans = 0;
    l(1, H + 1, r) {
        l(1, W + 1, c) {
            if (grid[r][c] == 'J') {
                ll cntI = preI[H][c] - preI[r][c];
                ll cntO = preO[r][W] - preO[r][c];

                ans += cntI * cntO;
            }
        }
    }

    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...