This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define NDEBUG
#ifdef NDEBUG
#define dbg(TXTMSG) if constexpr (false) cerr << "lol"
#define dbgv(VARN) ((void)0)
#define dbgfor(COND) if constexpr (false) for (COND)
#else
#define _GLIBCXX_DEBUG 1
#define _GLIBCXX_DEBUG_PEDANTIC 1
#pragma GCC optimize("trapv")
#define dbg(TXTMSG) cerr << "\n" << TXTMSG
#define dbgv(VARN) cerr << "\n" << #VARN << " = "<< VARN << ", line " << __LINE__ << "\n"
#define dbgfor(COND) for (COND)
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
#define e0 first
#define e1 second
constexpr ll INFTY = 2e18;
int main()
{
ll H,W;
cin >> H >> W;
vector<string> S(H);
for (ll i = 0; i < H; ++i)
{
cin >> S[i];
}
vector<vector<ll>> ingotsbelow(H,vector<ll>(W));
for (ll j = 0; j < W; ++j)
{
ingotsbelow[H-1][j] = (S[H-1][j]=='I');
}
for (ll i = H-2; i >= 0; --i)
{
for (ll j = 0; j < W; ++j)
{
ingotsbelow[i][j] = ingotsbelow[i+1][j] + (S[i][j]=='I');
}
}
dbgv('j');
vector<vector<ll>> linestoleft(H,vector<ll>(W));
for (ll i = 0; i < H; ++i)
{
dbgv('h');
if (S[i][0]=='J') linestoleft[i][0] = ingotsbelow[i][0];
else linestoleft[i][0]=0;
dbgv(i);
for (ll j = 1; j < W; ++j)
{
dbgv(i);
dbgv(j);
if (S[i][j]=='J') {
dbg(i);
linestoleft[i][j] = linestoleft[i][j-1] + ingotsbelow[i][j];
}
else {
dbgv(i);
dbgv(linestoleft[i][j]);
linestoleft[i][j]=linestoleft[i][j-1];
}
}
}
ll outp=0;
for (ll i = 0; i < H; ++i)
{
for (ll j = 0; j < W; ++j)
{
if (S[i][j]=='O')
{
outp+=linestoleft[i][j];
}
}
}
cout << outp;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |