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>
#define ii pair<int, int>
#define fi first
#define se second
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
using ll = long long;
const ll mod=1e9+7;
const int nx=3e3+5;
int n, m, a[nx][nx], r[nx][nx][3], c[nx][nx][3];
ll ans=0;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n>>m;
for(int i = 1; i <= n; i++)
{
string s;
cin>>s;
for(int j = 1; j <= m; j++)
{
if(s[j-1]=='J')
a[i][j]=0;
else if(s[j-1]=='O')
a[i][j]=1;
else a[i][j]=2;
for(int k = 0; k < 3; k++)
{
r[i][j][k]=r[i-1][j][k]+(a[i][j]==k);
c[i][j][k]=c[i][j-1][k]+(a[i][j]==k);
}
}
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
if(a[i][j]==0)
ans+=(r[n][j][2]-r[i][j][2])*(c[i][m][1]-c[i][j][1]);
}
}
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... |