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 ll long long int
#define pb push_back
#define mp make_pair
#define FOR(i,n) for(i=0;i<(n);i++)
#define FORe(i,n) for(i=1;i<=(n);i++)
#define FORr(i,a,b) for(i=(a);i<(b);i++)
#define ii pair<ll,ll>
#define vi vector<ll>
#define vii vector<ii>
#define ff first
#define ss second
#define cd complex<double>
#define vcd vector<cd>
#define ldd long double
#define all(x) (x).begin(),(x).end()
using namespace std;
const short int __PRECISION = 10;
const ll MOD = 1e9+7;
const ll INF = 1e17 + 1101;
const ll LOGN = 17;
const ll MAXN = 2e5+5;
const ll ROOTN = 320;
const ldd PI = acos(-1);
const ldd EPS = 1e-7;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll H,W,i,j,ans = 0;
cin>>H>>W;
char A[H][W];
ll ingot[H][W],orb[H][W];
FOR(i,H)
FOR(j,W)
{
cin>>A[i][j];
orb[i][j] = ingot[i][j] = 0;
}
for(i=H-1;i>=0;i--)
for(j=W-1;j>=0;j--)
if (A[i][j] == 'O')
{
ingot[i][j] = ((i == H-1) ? 0 : ingot[i+1][j]);
orb[i][j] = 1 + ((j<W-1) ? orb[i][j+1] : 0);
}
else if (A[i][j] == 'I')
{
orb[i][j] = ((j == W-1) ? 0 : orb[i][j+1]);
ingot[i][j] = 1 + ((i<H-1) ? ingot[i+1][j] : 0);
}
else
{
orb[i][j] = ((j == W-1) ? 0 : orb[i][j+1]);
ingot[i][j] = ((i == H-1) ? 0 : ingot[i+1][j]);
}
FOR(i,H)
FOR(j,W)
if (A[i][j] == 'J')
ans += orb[i][j]*ingot[i][j];
cout<<ans;
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... |