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()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<char>>grid(n + 1, vector<char>(m + 1));
for(int i = 1;i <= n;++i){
for(int j = 1;j <= m;++j){
cin >> grid[i][j];
}
}
vector<vector<int>>orbs(n + 1, vector<int>(m + 1));
for(int i = 1;i <= n;++i){
for(int j = m;j >= 1;--j){
if(j + 1 <= m)orbs[i][j] = orbs[i][j + 1] + (grid[i][j] == 'O');
else orbs[i][j] = (grid[i][j] == 'O');
}
}
vector<vector<int>>ingots(n + 1, vector<int>(m + 1));
for(int i = n;i >= 1;--i){
for(int j = 1;j <= m;++j){
if(i + 1 <= n)ingots[i][j] = ingots[i + 1][j] + (grid[i][j] == 'I');
else ingots[i][j] = (grid[i][j] == 'I');
}
}
long long res = 0;
for(int i = 1;i <= n;++i){
for(int j = 1;j <= m;++j){
if(grid[i][j] == 'J'){
res += ingots[i][j] * orbs[i][j];
}
}
}
cout << res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |