Submission #1179767

#TimeUsernameProblemLanguageResultExecution timeMemory
1179767bbartekBitaro the Brave (JOI19_ho_t1)C++20
100 / 100
365 ms247600 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define st first
#define nd second
#define pb push_back

const int maxn = 3e3+7;

int tab[maxn][maxn];
int sumy[maxn][maxn][3][2];

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

    int n,m;
    cin>>n>>m;

    string s;
    for(int i=0;i<n;i++){
        cin>>s;
        for(int j=0;j<m;j++){
            if(s[j] == 'J'){
                sumy[i+1][j+1][0][0]++;
                sumy[j+1][i+1][0][1]++;
                tab[i+1][j+1] = 0;
            }
            if(s[j] == 'O'){
                sumy[i+1][j+1][1][0]++;
                sumy[j+1][i+1][1][1]++;
                tab[i+1][j+1] = 1;
            }
            if(s[j] == 'I'){
                sumy[i+1][j+1][2][0]++;
                sumy[j+1][i+1][2][1]++;
                tab[i+1][j+1] = 2;
            }
        }
    }

    for(int i=n;i>=1;i--){
        for(int j=m;j>=1;j--){
            sumy[i][j][0][0] += sumy[i][j+1][0][0];
            sumy[i][j][1][0] += sumy[i][j+1][1][0];
            sumy[i][j][2][0] += sumy[i][j+1][2][0];
            sumy[j][i][0][1] += sumy[j][i+1][0][1];
            sumy[j][i][1][1] += sumy[j][i+1][1][1];
            sumy[j][i][2][1] += sumy[j][i+1][2][1];
        }
    }
    

    ll wyn = 0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(tab[i][j] == 0){
                wyn += (ll)sumy[i][j][1][0]*(ll)sumy[j][i][2][1];
            }
        }
    }

    cout<<wyn<<"\n";

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...