#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;
ll N,M;
vector<string> D;
bool inrange(pll pos) {
return 0<=pos.e0 && pos.e0<M && 0<=pos.e1 && pos.e1<N;
}
bool canhskewer(pll pos) {
if (!inrange({pos.e0-1,pos.e1}) || !inrange({pos.e0+1,pos.e1})) return false;
return D[pos.e1][pos.e0-1]=='R' && D[pos.e1][pos.e0]=='G' && D[pos.e1][pos.e0+1]=='W';
}
bool canvskewer(pll pos) {
if (!inrange({pos.e0,pos.e1-1}) || !inrange({pos.e0,pos.e1+1})) return false;
//dbgv(D[pos.e1][pos.e0]=='G');
return D[pos.e1-1][pos.e0]=='R' && D[pos.e1][pos.e0]=='G' && D[pos.e1+1][pos.e0]=='W';
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cin >> N >> M;
D.assign(N,"");
for (ll i = 0; i < N; ++i)
{
cin >> D[i];
assert(ll(D[i].size())==M);
}
vector<vector<ll>> dp_vert(N,vector<ll>(M));
vector<vector<ll>> dp_horiz(N,vector<ll>(M));
vector<vector<ll>> dp_no(N,vector<ll>(M));
dbgv(canvskewer({3,1}));
ll outp=0;
for (ll d = 0; d < (M+N-1); ++d)
{
pll pos;
if (d<M)
{
pos = {d,0};
}
else {
pos = {M-1,d-M+1};
}
dp_vert[pos.e1][pos.e0]=ll(canvskewer(pos));
dp_horiz[pos.e1][pos.e0]=ll(canhskewer(pos));
dp_no[pos.e1][pos.e0]=0;
pll oldpos = pos;
pos.e0-=1;
pos.e1+=1;
while (inrange(pos)) {
dp_no[pos.e1][pos.e0] = max({
dp_vert[oldpos.e1][oldpos.e0]
,dp_horiz[oldpos.e1][oldpos.e0]
,dp_no[oldpos.e1][oldpos.e0]
});
dp_vert[pos.e1][pos.e0] = canvskewer(pos) + max({
dp_vert[oldpos.e1][oldpos.e0]
,dp_no[oldpos.e1][oldpos.e0]
});
dp_horiz[pos.e1][pos.e0] = canhskewer(pos) + max({
dp_horiz[oldpos.e1][oldpos.e0]
,dp_no[oldpos.e1][oldpos.e0]
});
oldpos = pos;
pos.e0-=1;
pos.e1+=1;
}
outp+=max({
dp_vert[oldpos.e1][oldpos.e0]
,dp_horiz[oldpos.e1][oldpos.e0]
,dp_no[oldpos.e1][oldpos.e0]
});
dbgv(d << ":" << outp);
}
cout << outp;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
608 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
456 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
608 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
456 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
440 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
456 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
452 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
352 KB |
Output is correct |
39 |
Correct |
0 ms |
352 KB |
Output is correct |
40 |
Correct |
0 ms |
580 KB |
Output is correct |
41 |
Correct |
0 ms |
344 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
452 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
344 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
352 KB |
Output is correct |
51 |
Correct |
0 ms |
352 KB |
Output is correct |
52 |
Correct |
0 ms |
548 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
608 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
456 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
440 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
456 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
452 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
352 KB |
Output is correct |
39 |
Correct |
0 ms |
352 KB |
Output is correct |
40 |
Correct |
0 ms |
580 KB |
Output is correct |
41 |
Correct |
0 ms |
344 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
452 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
344 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
352 KB |
Output is correct |
51 |
Correct |
0 ms |
352 KB |
Output is correct |
52 |
Correct |
0 ms |
548 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
1 ms |
348 KB |
Output is correct |
55 |
Correct |
1 ms |
860 KB |
Output is correct |
56 |
Correct |
1 ms |
860 KB |
Output is correct |
57 |
Correct |
1 ms |
1116 KB |
Output is correct |
58 |
Correct |
32 ms |
25944 KB |
Output is correct |
59 |
Correct |
421 ms |
230540 KB |
Output is correct |
60 |
Correct |
432 ms |
231004 KB |
Output is correct |
61 |
Correct |
417 ms |
230800 KB |
Output is correct |
62 |
Correct |
0 ms |
604 KB |
Output is correct |
63 |
Correct |
388 ms |
223032 KB |
Output is correct |
64 |
Correct |
383 ms |
230964 KB |
Output is correct |
65 |
Correct |
382 ms |
230932 KB |
Output is correct |
66 |
Correct |
377 ms |
231000 KB |
Output is correct |
67 |
Correct |
379 ms |
230768 KB |
Output is correct |
68 |
Correct |
385 ms |
230992 KB |
Output is correct |
69 |
Correct |
386 ms |
230792 KB |
Output is correct |
70 |
Correct |
30 ms |
25948 KB |
Output is correct |
71 |
Correct |
30 ms |
25952 KB |
Output is correct |
72 |
Correct |
28 ms |
25948 KB |
Output is correct |
73 |
Correct |
31 ms |
25944 KB |
Output is correct |
74 |
Correct |
28 ms |
25944 KB |
Output is correct |
75 |
Correct |
29 ms |
25948 KB |
Output is correct |
76 |
Correct |
31 ms |
26204 KB |
Output is correct |
77 |
Correct |
30 ms |
25948 KB |
Output is correct |
78 |
Correct |
30 ms |
25948 KB |
Output is correct |
79 |
Correct |
29 ms |
25948 KB |
Output is correct |
80 |
Correct |
30 ms |
25948 KB |
Output is correct |
81 |
Correct |
29 ms |
25948 KB |
Output is correct |
82 |
Correct |
28 ms |
25948 KB |
Output is correct |
83 |
Correct |
28 ms |
26064 KB |
Output is correct |
84 |
Correct |
33 ms |
26116 KB |
Output is correct |
85 |
Correct |
29 ms |
25936 KB |
Output is correct |
86 |
Correct |
29 ms |
25980 KB |
Output is correct |
87 |
Correct |
29 ms |
25948 KB |
Output is correct |
88 |
Correct |
31 ms |
25944 KB |
Output is correct |
89 |
Correct |
29 ms |
25944 KB |
Output is correct |
90 |
Correct |
32 ms |
26120 KB |
Output is correct |