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;
#define int long long
#define sp << " " <<
#define nl << "\n"
signed main(){
cin.tie(0)->sync_with_stdio(0);
int h, w; cin >> h >> w;
char g[h][w];
int orbs[h][w], ingots[h][w];
for(int i=0; i<h; ++i)
for(int j=0; j<w; ++j)
orbs[i][j] = ingots[i][j] = 0;
for(int i=0; i<h; ++i){
for(int j=0; j<w; ++j){
cin >> g[i][j];
if(g[i][j]=='O') ++orbs[i][j];
if(g[i][j]=='I') ++ingots[i][j];
}
}
for(int i=h-2; i>=0; --i){
for(int j=w-2; j>=0; --j){
orbs[i][j] += orbs[i][j+1];
ingots[i][j] += ingots[i+1][j];
}
}
int ans = 0;
for(int i=0; i<h; ++i){
for(int j=0; j<w; ++j){
if(g[i][j]=='J') ans += (orbs[i][j]*ingots[i][j]);
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |