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 all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
const int maxn= 3030;
int n, m;
char mat[maxn][maxn];
int J[maxn][maxn], I[maxn][maxn];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
cin >> mat[i][j];
for(int i = 1; i <= n; i++) {
for(int j = m; j; j--) {
J[i][j] = J[i][j+1] + (mat[i][j] == 'O');
}
}
for(int i = n; i; i--) {
for(int j = 1; j <= m; j++) {
I[i][j] = I[i+1][j] + (mat[i][j] == 'I');
}
}
ll ans = 0;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++) {
if(mat[i][j] != 'J') continue;
ans += J[i][j] * I[j][j];
}
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... |