#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e3;
int n, m, O[maxn + 1][maxn + 1], I[maxn + 1][maxn + 1];
string s[maxn + 1];
long long res = 0;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; ++i){
cin >> s[i];
s[i] = " " + s[i];
}
for (int i = 1; i <= n; ++i){
for (int j = 1; j <= m; ++j){
O[i][j] = O[i][j - 1] + (s[i][j] == 'O');
}
}
for (int j = 1; j <= m; ++j){
for (int i = 1; i <= n; ++i){
I[i][j] = I[i - 1][j] + (s[i][j] == 'I');
}
}
for (int i = 1; i <= n; ++i){
for (int j = 1; j <= m; ++j) if (s[i][j] == 'J'){
res += (O[i][m] - O[i][j - 1]) * (I[n][j] - I[i - 1][j]);
}
}
cout << res;
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... |