Submission #1158704

#TimeUsernameProblemLanguageResultExecution timeMemory
1158704wjliangtpeBitaro the Brave (JOI19_ho_t1)C++20
100 / 100
220 ms108052 KiB
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define oo 10000000000000001
vector<pair<int,int> > J;
long long ans;
int h,w,preo[3005][3005],prei[3005][3005];
char c[3005][3005];
signed main(){
    ios::sync_with_stdio(0),cin.tie(0);
    cin>>h>>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>c[i][j];
            if(c[i][j]=='J') J.push_back({i,j});
        }
    }
    for(int i=0;i<=h;i++){
        for(int j=0;j<=w;j++){
            preo[i][j]=0;
            prei[i][j]=0;
        }
    }
    for(int i=h-1;i>=0;i--){
        for(int j=w-1;j>=0;j--){
            preo[i][j]=preo[i][j+1];
            if(c[i][j]=='O') preo[i][j]++;
            prei[i][j]=prei[i+1][j]+((c[i][j]=='I')?1:0);
        }
    }
    for(auto p:J){
        int x=p.first,y=p.second;
        ans+=preo[x][y]*prei[x][y];
    }
    cout<<ans<<'\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...