#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
496 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
444 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
496 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
444 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
6 ms |
3676 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
2648 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
7 ms |
4956 KB |
Output is correct |
19 |
Correct |
6 ms |
4700 KB |
Output is correct |
20 |
Correct |
6 ms |
4956 KB |
Output is correct |
21 |
Correct |
7 ms |
4956 KB |
Output is correct |
22 |
Correct |
6 ms |
4700 KB |
Output is correct |
23 |
Correct |
6 ms |
4888 KB |
Output is correct |
24 |
Correct |
8 ms |
4956 KB |
Output is correct |
25 |
Correct |
6 ms |
4700 KB |
Output is correct |
26 |
Correct |
6 ms |
4956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
496 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
444 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
6 ms |
3676 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
2648 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
7 ms |
4956 KB |
Output is correct |
19 |
Correct |
6 ms |
4700 KB |
Output is correct |
20 |
Correct |
6 ms |
4956 KB |
Output is correct |
21 |
Correct |
7 ms |
4956 KB |
Output is correct |
22 |
Correct |
6 ms |
4700 KB |
Output is correct |
23 |
Correct |
6 ms |
4888 KB |
Output is correct |
24 |
Correct |
8 ms |
4956 KB |
Output is correct |
25 |
Correct |
6 ms |
4700 KB |
Output is correct |
26 |
Correct |
6 ms |
4956 KB |
Output is correct |
27 |
Correct |
236 ms |
153388 KB |
Output is correct |
28 |
Correct |
1 ms |
856 KB |
Output is correct |
29 |
Correct |
16 ms |
12124 KB |
Output is correct |
30 |
Correct |
1 ms |
860 KB |
Output is correct |
31 |
Correct |
178 ms |
113972 KB |
Output is correct |
32 |
Correct |
219 ms |
160596 KB |
Output is correct |
33 |
Correct |
292 ms |
161084 KB |
Output is correct |
34 |
Correct |
217 ms |
132168 KB |
Output is correct |
35 |
Correct |
225 ms |
160980 KB |
Output is correct |
36 |
Correct |
232 ms |
161168 KB |
Output is correct |
37 |
Correct |
262 ms |
161616 KB |
Output is correct |
38 |
Correct |
156 ms |
113092 KB |
Output is correct |
39 |
Correct |
148 ms |
113488 KB |
Output is correct |