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>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=3005;
char a[N][N];
int cntO[N][N],cntI[N][N];
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int h,w;
cin>>h>>w;
char a[h][w];
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
cin>>a[i][j];
}
}
for(int i=0;i<h;i++){
int cnt=0;
for(int j=w-1;j>=0;j--){
if(a[i][j]=='O')cnt++;
cntO[i][j]=cnt;
}
}
for(int i=0;i<w;i++){
int cnt=0;
for(int j=h-1;j>=0;j--){
if(a[j][i]=='I')cnt++;
cntI[j][i]=cnt;
}
}
int ans=0;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(a[i][j]=='J')ans+=cntI[i][j]*cntO[i][j];
}
}
cout<<ans<<"\n";
}
/*
3 4
JOIJ
JIOO
IIII
4 4
JJOO
JJOO
IIJO
IIIJ
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |