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;
int sufr[3000][3000],sufc[3000][3000],val[3000][3000];
char ch;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int t=1,n,m;
// cin >> t;
while (t--){
cin >> n >> m;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
cin >> ch;
if (ch == 'J'){
val[i][j] = 0;
}
if (ch == 'O'){
val[i][j] = 1;
}
if (ch == 'I'){
val[i][j] = 2;
}
}
}
// sufr[i][j] orbs in row i, after j
// sufc[i][j] ingots in column j, after i
for (int i = 0; i < n; i++){
sufr[i][m-1] = (val[i][m-1] == 1);
for (int j = m-2; j >= 0; j--){
sufr[i][j] = sufr[i][j+1] + (val[i][j] == 1);
}
}
for (int j = 0; j < m; j++){
sufc[n-1][j] = (val[n-1][j] == 2);
for (int i = n-2; i >= 0; i--){
sufc[i][j] = sufc[i+1][j] + (val[i][j] == 2);
}
}
int ans = 0;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
if (!val[i][j]){
ans += (sufr[i][j]*sufc[i][j]);
}
}
}
cout << ans << "\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... |