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;
typedef long long ll;
int main() {
int h,w; cin>>h>>w;
vector<string> a;
for (int i=0; i<h; i++) {
string s; cin>>s;
a.push_back(s);
}
vector<vector<int>> osf(h,vector<int>(w,0));
for (int i=0; i<h; i++) {
if (a[i][w-1]=='O') osf[i][w-1]=1;
for (int j=w-2; j>=0; j--) {
if (a[i][j]=='O') osf[i][j]=osf[i][j+1]+1;
else osf[i][j]=osf[i][j+1];
}
}
vector<vector<int>> isf(h,vector<int>(w,0));
for (int j=0; j<w; j++) {
if (a[h-1][j]=='I') isf[h-1][j]=1;
for (int i=h-2; i>=0; i--) {
if (a[i][j]=='I') isf[i][j]=isf[i+1][j]+1;
else isf[i][j]=isf[i+1][j];
}
}
ll ans=0;
for (int i=0; i<h; i++) {
for (int j=0; j<w; j++) {
if (a[i][j]=='J') {
ans+=osf[i][j]*isf[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... |