Submission #1258755

#TimeUsernameProblemLanguageResultExecution timeMemory
1258755quanh_2605Bitaro the Brave (JOI19_ho_t1)C++20
100 / 100
324 ms150592 KiB
#include <bits/stdc++.h>
using namespace std;

long long n, m, ans;
char a[3005][3005];
long long row[3005], col[3005];
long long bopc[3005][3005], pr[3005][3005];

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

    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> a[i][j];
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (a[i][j] == '0') row[i]++;
            if (a[i][j] == 'I') col[j]++;
        }
    }

    for (int j = 1; j <= m; j++) {
        for (int i = 1; i <= n; i++) {
            bopc[i][j] = bopc[i - 1][j] + (a[i][j] == 'I');
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            pr[i][j] = pr[i][j - 1] + (a[i][j] == 'O');
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (a[i][j] == 'J') {
                ans += (pr[i][m] - pr[i][j]) * (bopc[n][j] - bopc[i][j]);
            }
        }
    }

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