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(false);
cin.tie(NULL);
int h, w;
cin >> h >> w;
string arr[h];
for(int i=0; i<h; i++){
cin >> arr[i];
}
int ingots[h][w];
for(int i=0; i<w; i++){
if(arr[h-1][i]=='I'){
ingots[h-1][i]=1;
}
else{
ingots[h-1][i]=0;
}
}
for(int i=h-2; i>=0; i--){
for(int j=0; j<w; j++){
ingots[i][j]=ingots[i+1][j];
if(arr[i][j]=='I'){
ingots[i][j]++;
}
}
}
int orbs[h][w];
for(int i=0; i<h; i++){
if(arr[i][w-1]=='O'){
orbs[i][w-1]=1;
}
else{
orbs[i][w-1]=0;
}
}
for(int i=0; i<h; i++){
for(int j=w-2; j>=0; j--){
orbs[i][j]=orbs[i][j+1];
if(arr[i][j]=='O'){
orbs[i][j]++;
}
}
}
long long finans = 0;
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
if(arr[i][j]=='J'){
finans += (long long) (orbs[i][j]*ingots[i][j]);
}
}
}
cout << finans << '\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... |