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 ll long long
#define pll pair<int, int>
#define pb push_back
#define fi first
#define se second
using namespace std;
const int MX=3005;
int h, w, prefr[MX][MX], prefc[MX][MX];
ll ans;
char g[MX][MX];
int main(){
cin >> h >> w;
vector<pll> start;
for(int i=1; i<=h; i++){
for(int j=1; j<=w; j++){
cin >> g[i][j];
if(g[i][j]=='J') start.pb({i, j});
prefr[i][j]=prefr[i][j-1];
prefc[j][i]=prefc[j][i-1];
if(g[i][j]=='O') prefr[i][j]++;
if(g[i][j]=='I') prefc[j][i]++;
}
}
for(auto i : start){
int r=i.fi, c=i.se;
// cout << r << " " << c << endl;
int oo=(prefr[r][w]-prefr[r][c]);
int ii=(prefc[c][h]-prefc[c][r]);
// cout << "nilai " << ii << " " << oo << endl;
ans+=ii*oo;
}
cout << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |