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;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
void solve(){
int n, m;
cin >> n >> m;
vector<vector<char>> grid(n, vector<char>(m));
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++)
cin >> grid[i][j];
}
vector<vi> i_down(n+1, vi(m+1)), o_right(n+1, vi(m+1));
for(int i = n-1; i >= 0; i--){
for(int j = 0; j < m; j++){
i_down[i][j] = i_down[i+1][j];
if(grid[i][j] == 'I')
i_down[i][j]++;
}
}
for(int j = m-1; j >= 0; j--){
for(int i = 0; i < n; i++){
o_right[i][j] = o_right[i][j+1];
if(grid[i][j] == 'O')
o_right[i][j]++;
}
}
ll ans = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(grid[i][j] == 'J')
ans += o_right[i][j]*i_down[i][j];
}
}
cout << ans << '\n';
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |