Submission #1258786

#TimeUsernameProblemLanguageResultExecution timeMemory
1258786khanhanBitaro the Brave (JOI19_ho_t1)C++20
100 / 100
228 ms44552 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

char a[3005][3005];
int dem[3005][3005];   

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

    int H, W;
    cin >> H >> W;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            cin >> a[i][j];
        }
    }

     
    for (int j = 1; j <= W; j++) {
        int cur = 0;
        for (int i = H; i >= 1; i--) {
            dem[i][j] = cur;
            if (a[i][j] == 'I') cur++;
        }
    }

    ll ans = 0;
     
    for (int i = 1; i < H; i++) {
        ll sum = 0;
        for (int j = 1; j <= W; j++) {
            if (a[i][j] == 'J') {
                sum += dem[i][j];   
            }
            if (a[i][j] == 'O') {
                ans += sum;         
            }
        }
    }

    cout << ans << "\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...