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 ff first
#define ss second
#define ll long long
#define pb push_back
#define pii pair<ll,ll>
ll psi[3001][3001], pso[3001][3001];
int main(){
ll ans=0;
ll n, m;
cin >> n >> m;
char c[n+1][m+1];
vector <pii> pos;
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
cin >> c[i][j];
if(j>0) pso[i][j]=pso[i][j-1];
if(i>0) psi[i][j]=psi[i-1][j];
if(c[i][j] == 'J') pos.pb({i,j});
else if(c[i][j] == 'O'){
if(j>0) pso[i][j]++;
else pso[i][j]=1;
}
else{
if(i>0) psi[i][j]++;
else psi[i][j]=1;
}
}
}
// for(int i=0; i<n; i++){
// cout << psi[i][0] << " ";
// }
for(auto x:pos){
ll a=x.ff, b=x.ss;
ll I=psi[n-1][b]-psi[a][b], O=pso[a][m-1]-pso[a][b];
// cout << I*O << endl;
ans+=I*O;
}
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... |