Submission #131177

#TimeUsernameProblemLanguageResultExecution timeMemory
131177losmi247Bitaro the Brave (JOI19_ho_t1)C++14
100 / 100
223 ms89592 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e3+45;

char a[N][N];
int cnti[N][N],cnto[N][N];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int h,w;
    cin >> h >> w;
    for(int i = 1; i <= h; i++){
        string s;
        cin >> s;
        for(int j = 1; j <= w; j++){
            a[i][j] = s[j-1];
            cnto[i][j] = cnto[i][j-1]+(a[i][j] == 'O');
        }
    }
    for(int j = 1; j <= w; j++){
        for(int i = 1; i <= h; i++){
            cnti[j][i] = cnti[j][i-1]+(a[i][j] == 'I');
        }
    }
    ll sol = 0;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(a[i][j] != 'J'){
                continue;
            }
            ll iovi = cnti[j][h]-cnti[j][i-1],oovi = cnto[i][w]-cnto[i][j-1];
            sol += iovi*oovi;
        }
    }
    cout << sol << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...