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;
int h,w;
char space[3007][3007];
long long ans,qso[3007][3007],qsi[3007][3007];
queue<pair<int,int>> q;
int main()
{
cin>>h>>w;
for(int i=1;i<=h;i++)
{
for(int j=1;j<=w;j++)
{
cin>>space[i][j];
if(space[i][j]=='J')
{
q.push({i,j});
}
}
}
for(int i=1;i<=h;i++)
{
for(int j=1;j<=w;j++)
{
if(space[i][j]=='I')
qsi[i][j]=qsi[i-1][j]+1;
else
qsi[i][j]=qsi[i-1][j];
if(space[i][j]=='O')
qso[i][j]=qso[i][j-1]+1;
else
qso[i][j]=qso[i][j-1];
}
}
while(!q.empty())
{
int x=q.front().first;
int y=q.front().second;
q.pop();
ans+=(qsi[h][y]-qsi[x][y])*(qso[x][w]-qso[x][y]);
// cout<<x<<" "<<y<<" "<<ans<<" "<<qsi[h][y]<<" "<<qso[x][w]<<"\n";
}
cout<<ans;
// for(int i=1;i<=h;i++)
// {
// for(int j=1;j<=w;j++)
// {
// cout<<qsi[i][j]<<" ";
// }
// 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... |