Submission #895614

#TimeUsernameProblemLanguageResultExecution timeMemory
895614AndreyBitaro the Brave (JOI19_ho_t1)C++14
100 / 100
332 ms114900 KiB
#include<bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin >> n >> m;
    int haha[n][m];
    char p;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            cin >> p;
            if(p == 'J') {
                haha[i][j] = 0;
            }
            else if(p == 'O') {
                haha[i][j] = 1;
            }
            else {
                haha[i][j] = 2;
            }
        }
    }
    int br1[n][m];
    int br2[n][m];
    for(int i = 0; i < n; i++) {
        br1[i][m-1] = 0;
        if(haha[i][m-1] == 1) {
            br1[i][m-1]++;
        }
        for(int j = m-2; j >= 0; j--) {
            br1[i][j] = br1[i][j+1];
            if(haha[i][j] == 1) {
                br1[i][j]++;
            }
        }
    }
    for(int i = n-1; i >= 0; i--) {
        for(int j = 0; j < m; j++) {
            if(i == n-1) {
                br2[i][j] = 0;
            }
            else {
                br2[i][j] = br2[i+1][j];
            }
            if(haha[i][j] == 2) {
                br2[i][j]++;
            }
        }
    }
    long long ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if(haha[i][j] == 0) {
                ans+=br1[i][j]*br2[i][j];
            }
        }
    }
    cout << ans;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...