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 long long
signed main()
{
int nbLigs, nbCols;
cin >> nbLigs >> nbCols;
vector<string> tab(nbLigs);
for(int iL =0; iL < nbLigs; iL++)
{
cin >>tab[iL];
}
vector<vector<int>>cumulBotToTop(nbLigs+1, vector<int>(nbCols+1, 0));
vector<vector<int>>cumulRightToLeft(nbLigs+1, vector<int>(nbCols+1, 0));
for(int iL = nbLigs-1; iL >=0; iL--)
{
for(int iC = nbCols-1; iC >= 0; iC--)
{
cumulRightToLeft[iL][iC] = cumulRightToLeft[iL][iC+1];
if(tab[iL][iC] == 'O')
cumulRightToLeft[iL][iC]++;
}
}
for(int iC = nbCols-1; iC >= 0; iC--)
{
for(int iL = nbLigs-1; iL >=0; iL--)
{
cumulBotToTop[iL][iC] = cumulBotToTop[iL+1][iC];
if(tab[iL][iC] == 'I')
cumulBotToTop[iL][iC]++;
}
}
int ans = 0;
for(int iL = 0; iL < nbLigs; iL++)
{
for(int iC = 0; iC < nbCols; iC++)
{
if(tab[iL][iC] == 'J')
{
ans += cumulBotToTop[iL][iC] * cumulBotToTop[iL][iC];
}
}
}
printf("%lld\n", 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... |