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;
#define ll long long
#define fi first
#define se second
#define pb push_back
#define skdkdjfkv ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void solve(){
ll h, w;
cin >> h >> w;
string s[h+1];
for(int i=1; i<=h; i++){
cin >> s[i];
}
ll sufho[h+5][w+5], sufvi[w+5][h+5];
for(int i=1; i<=h; i++){
sufho[i][w+1]=0;
for(int j=w; j>=1; j--){
sufho[i][j]=sufho[i][j+1]+(s[i][j-1]=='O');
}
}
for(int j=1; j<=w; j++){
sufvi[j][h+1]=0;
for(int i=h; i>=1; i--){
sufvi[j][i]=sufvi[j][i+1]+(s[i][j-1]=='I');
}
}
ll ans=0;
for(int i=1; i<=h; i++){
for(int j=1; j<=w; j++){
if(s[i][j-1]=='J'){
ans+=sufho[i][j+1]*sufvi[j][i+1];
}
}
}
cout << ans;
}
int main(){
skdkdjfkv
ll tc=1;
//cin >> tc;
while(tc--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |