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;
vector<vector<int>> a;
vector<vector<int>> r;
vector<vector<int>> b;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int h,w;
cin >> h >> w;
a.resize(h);
for(int i =0;i < h;++i)
{
a[i].resize(w);
for(int j = 0;j < w;++j)
{
char x;
cin >> x;
a[i][j] = (x == 'J' ? 0 : (x == 'O' ? 1 : 2));
}
}
r.resize(h);
for(int i = 0;i < h;++i)
{
r[i].resize(w);
for(int j = w-1;j >= 0;--j)
{
r[i][j] = (j == w-1 ? 0 : r[i][j+1] + (a[i][j+1] == 1));
}
}
b.resize(h);
for(int i = h-1;i >= 0;--i)
{
b[i].resize(w);
for(int j = 0;j < w;++j)
{
b[i][j] = (i == h-1 ? 0 : b[i+1][j] + (a[i+1][j] == 2));
}
}
int64_t ans = 0;
for(int i = 0;i < h;++i)
{
for(int j = 0;j < w;++j)
{
ans += (a[i][j] == 0)*(r[i][j]*b[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... |