Submission #1348534

#TimeUsernameProblemLanguageResultExecution timeMemory
1348534faqinyeagerBitaro the Brave (JOI19_ho_t1)C++20
100 / 100
295 ms152984 KiB
#include <bits/stdc++.h>
using namespace std;

const long long int MOD = (int)1e9 + 7;
const long long int mxN = (int)1e5 + 7;

int main(){
    int H, W;
    cin >> H >> W;
    vector<string> s(H);
    for(int i = 0; i < H; i++){
        cin >> s[i];
    }
    vector<vector<long long int>> icnt(H, vector<long long int>(W, 0)), ocnt(H, vector<long long int>(W, 0));
    
    for(int j = 0; j < W; j++){
        if(s[H - 1][j] == 'I') icnt[H - 1][j]++;
    }
    
    for(int i = H - 2; i >= 0; i--){
        for(int j = 0; j < W; j++){
            icnt[i][j] = icnt[i + 1][j];
            if(s[i][j] == 'I') icnt[i][j]++;
        }
    }

    for(int i = 0; i < H; i++){
        if(s[i][W - 1] == 'O') ocnt[i][W - 1]++;
    }
    for(int j = W - 2; j >= 0; j--){
        for(int i = 0; i < H; i++){
            ocnt[i][j] = ocnt[i][j + 1];
            if(s[i][j] == 'O') ocnt[i][j]++;
        }
    }
    long long int sum = 0;
    
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(s[i][j] == 'J') sum += ocnt[i][j] * icnt[i][j];
        }
    }

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