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
vector<vector<int>> a;
vector<vector<int>> r[3];
vector<vector<int>> b[3];
signed 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));
}
}
for(int x = 0;x < 3;++x)
{
r[x].resize(h);
for(int i = 0;i < h;++i)
{
r[x][i].resize(w);
for(int j = w-1;j >= 0;--j)
{
r[x][i][j] = (j == w-1 ? 0 : r[x][i][j+1] + (a[i][j+1] == x));
}
}
}
for(int x = 0;x < 3;++x)
{
b[x].resize(h);
for(int i = h-1;i >= 0;--i)
{
b[x][i].resize(w);
for(int j = 0;j < w;++j)
{
b[x][i][j] = (i == h-1 ? 0 : b[x][i+1][j] + (a[i+1][j] == x));
}
}
}
int ans = 0;
for(int i = 0;i < h;++i)
{
for(int j = 0;j < w;++j)
{
int f = (a[i][j]+1)%3;
int s = (a[i][j]+2)%3;
ans += (a[i][j] == 0)*(r[f][i][j]*b[s][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... |