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>
#include <iostream>
using namespace std;
#define int int64_t
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m; cin>>n>>m;
vector<string>v;
vector<vector<int>>orb(n+1, vector<int>(m+1));
vector<vector<int>>ing(n+1, vector<int>(m+1));
for(int i = 1; i<=n; ++i){
string a; cin>>a;
v.push_back(a);
for(int j = 1; j<=m; ++j){
char c = a[j-1];
if(c == 'O') orb[i][j] = 1 + orb[i][j-1];
if(c == 'I') ing[i][j] = 1 + ing[i-1][j];
if(!orb[i][j]) orb[i][j] = orb[i][j-1];
if(!ing[i][j]) ing[i][j] = ing[i-1][j];
}
}
/*
for(auto u: orb){
for(auto v: u) cout<<v<<" ";
cout<<endl;
}
cout<<endl;
for(auto u: ing){
for(auto v: u) cout<<v<<" ";
cout<<endl;
}
cout<<endl;
*/
int ans = 0;
for(int i = 1; i<=n; ++i){
for(int j = 1; j<=m; ++j){
int o = orb[i][m];
int in = ing[n][j];
if(v[i-1][j-1] == 'J') ans += (o-orb[i][j]) * (in - ing[i][j]);
}
}
cout<<ans;
cout<<'\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... |