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 main()
{
//freopen("i.txt","r",stdin);
cin.tie(0);
ios_base::sync_with_stdio(false);
int rows, cols;
cin >> rows >> cols;
int arr[rows][cols];
for(int r = 0;r < rows;r++){
string s;
cin >> s;
for(int c = 0;c < cols;c++){
if(s[c] == 'J') arr[r][c] = 0;
else if(s[c] == 'O') arr[r][c] = 1;
else arr[r][c] = 2;
}
}
int O[rows][cols];
int I[rows][cols];
for(int r = 0;r < rows;r++){
for(int c = 0;c < cols;c++){
O[r][c] = 0;
I[r][c] = 0;
}
}
for(int r = 0;r < rows;r++){
for(int c = cols-1;c >= 0;c--){
if(arr[r][c] == 1) O[r][c]++;
if(c != cols-1) O[r][c] += O[r][c+1];
}
}
for(int c = 0;c < cols;c++){
for(int r = rows-1;r >= 0;r--){
if(arr[r][c] == 2) I[r][c]++;
if(r != rows-1) I[r][c] += I[r+1][c];
}
}
long long ans = 0ll;
for(int r = 0;r < rows;r++){
for(int c = 0;c < cols;c++){
if(arr[r][c] == 0){
long long x = O[r][c];
long long y = I[r][c];
ans += x * y;
}
}
}
cout << ans;
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... |