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 int64_t
void calc(vector<vector<int>> &aha, int h, int w, bool how){
if(how){
for(int i=h-1;i>=0;i--){
for(int j=w-2;j>=0;j--){
aha[i][j]+=aha[i][j+1];
}
}
return;
}
for(int i=w-1;i>=0;i--){
for(int j=h-2;j>=0;j--){
aha[j][i]+=aha[j+1][i];
}
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int h,w;
cin>>h>>w;
vector<string> grid(h);
vector<vector<int>> orbs(h,vector<int> (w,0));
vector<vector<int>> ingots(h,vector<int> (w,0));
for(int i=0;i<h;i++){
cin>>grid[i];
for(int j=0;j<w;j++){
if(grid[i][j]=='O'){
orbs[i][j]++;
}else if(grid[i][j]=='I'){
ingots[i][j]++;
}
}
}
calc(orbs,h,w,true);
calc(ingots,h,w,false);
int sum=0;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(grid[i][j]=='J'){
sum+=orbs[i][j]*ingots[i][j];
}
}
}
cout<<sum<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |