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;
const int maxn = 3e3+10;
int h, w;
char mat[maxn][maxn];
long long sumO[maxn][maxn], sumI[maxn][maxn];
int main()
{
cin >> h >> w;
for(int i = 1 ; i <= h ; ++i)
for(int j = 1 ; j <= w; ++j)
cin >> mat[i][j];
// make a sum of eche O
for(int i = 1 ; i <= h ; ++i)
{
for(int j = 1 ; j <= w; ++j)
{
sumO[i][j] = sumO[i][j - 1];
if(mat[i][j] == 'O')
sumO[i][j]++;
}
}
for(int i = 1 ; i <= w ; ++i)
{
for(int j = 1 ; j <= h; ++j)
{
sumI[j][i] = sumI[j - 1][i];
if(mat[j][i] == 'I')
sumI[j][i]++;
}
}
long long resp = 0;
for(int i = 1 ; i <= h ; ++i)
{
for(int j = 1 ; j <= w; ++j)
{
if(mat[i][j] == 'J')
{
long long O = sumO[i][w] - sumO[i][j];
long long I = sumI[h][j] - sumI[i - 1][j];
//cout << i << " " << j << " " << O << " " << I << "\n" ;
resp += (O*I);
}
}
}
cout << resp << "\n";
/*for(int i = 1 ; i <= h ; ++i)
{
for(int j = 1 ; j <= w; ++j)
{
cout << sumO[i][j] <<" ";
}
cout << "\n";
}
cout << "\n";
for(int i = 1 ; i <= h ; ++i)
{
for(int j = 1 ; j <= w; ++j)
{
cout << sumI[i][j] <<" ";
}
cout << "\n";
}*/
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |