This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int O[3005][3005];
int I[3005][3005];
char c[3005][3005];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int H,W;
cin>>H>>W;
for(int i=1;i<=H;i++){
for(int j=1;j<=W;j++){
cin>>c[i][j];
O[i][j]=O[i-1][j]+O[i][j-1]-O[i-1][j-1];
I[i][j]=I[i-1][j]+I[i][j-1]-I[i-1][j-1];
if(c[i][j]=='O') O[i][j]++;
if(c[i][j]=='I') I[i][j]++;
}
}
long long ans=0;
for(int i=1;i<=H;i++){
for(int j=1;j<=W;j++){
if(c[i][j]=='J'){
long long a=O[i][W]-O[i-1][W]-O[i][j]+O[i-1][j];
long long b=I[H][j]-I[H][j-1]-I[i][j]+I[i][j-1];
ans+=a*b;
}
}
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |