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 ll long long
using namespace std;
int main()
{
int H,W; cin >> H >> W;
vector<vector<ll>> suforbs(H,vector<ll>(W)), sufing(W,vector<ll>(H));
vector<string> grid(H);
for(int i = 0;i<H;++i){
cin >> grid[i];
}
for(int i = 0;i<H;++i){
suforbs[i][W-1] = ((grid[i][W-1] == 'O') ? 1 : 0);
for(int j = W-2;j>=0;--j){
if(grid[i][j] == 'O') suforbs[i][j] = suforbs[i][j+1]+1;
else suforbs[i][j] = suforbs[i][j+1];
}
}
for(int i = 0;i<W;++i){
sufing[i][H-1] = ((grid[H-1][i] == 'I') ? 1 : 0);
//cout << "ok";
for(int j = H-2;j>=0;--j){
if(grid[j][i] == 'I') sufing[i][j] = sufing[i][j+1]+1;
else sufing[i][j] = sufing[i][j+1];
}
//cout << "ok";
}
//cout << "ok";
ll ans = 0;
for(int i = 0;i<H-1;++i){
for(int j = 0;j<W-1;++j){
if(grid[i][j] == 'J'){
ans += suforbs[i][j+1]*sufing[j][i+1];
}
}
}
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... |