#include <bits/stdc++.h>
#define int long long
using namespace std;
const int nx =3005;
string grid[nx];
int h, w, qso[nx][nx], qsi[nx][nx], ans = 0;
signed main(){
cin.tie(NULL)->sync_with_stdio(false);
cin >> h >> w;
for(int i=1; i<=h; i++){
cin >> grid[i];
for(int j=0; j<w; j++){
if(grid[i][j]=='O'){
// cout << "O\n";
qso[i][j+1]++;
} else if(grid[i][j]=='I'){
// cout << "I\n";
qsi[i][j+1]++;
}
qso[i][j+1]+=qso[i][j];
qsi[i][j+1]+=qsi[i-1][j+1];
}
}
for(int i=1; i<=h; i++){
for(int j=0; j<w; j++){
if(grid[i][j]=='J'){
ans+=((qso[i][w] - qso[i][j+1])*(qsi[h][j+1] - qsi[i][j+1]));
// cout << "i = " << i << " j = " << j+1 << "\n";
// cout << qso[i][w] << ' ' << qso[i][j+1] << ' ' << qsi[h][j+1] << ' ' << qsi[i][j+1] << "\n";
}
}
}
cout << ans;
// for(int i=1; i<=h; i++){
// for(int j=1; j<=w; j++) cout << qso[i][j] << ' ';
// cout << "\n";
// }
// cout << "----------------------------\n";
// for(int i=1; i<=h; i++){
// for(int j=1; j<=w; j++) cout << qsi[i][j] << ' ';
// cout << "\n";
// }
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... |