#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 6e3 + 16;
const ll Log2 = 19;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;
///Road to EF/M
char a[N][N];
ll n,m,ans;
ll dx[3] = {0,1,0};
ll dy[3] = {0,0,1};
bool aval[N][N][5];
bool chk(ll x,ll y,ll dir){
ll A2 = x + dx[dir],B2 = y + dy[dir];
ll A1 = x - dx[dir],B1 = y - dy[dir];
return a[A1][B1] == 'R' && a[A2][B2] == 'W' && a[x][y] == 'G';
}
ll dp[N][3],dia;
ll f(ll row,ll prv){
if (row == dia) return 0;
if (dp[row][prv] != -1) return dp[row][prv];
ll ans = f(row + 1,0);
if (!prv){
if (aval[row][dia - row][1]) ans = max(ans,1 + f(row + 1,1));
if (aval[row][dia - row][2]) ans = max(ans,1 + f(row + 1,2));
}
if (prv == 1){
if (aval[row][dia - row][1]) ans = max(ans,1 + f(row + 1,1));
}
if (prv == 2){
if (aval[row][dia - row][2]) ans = max(ans,1 + f(row + 1,2));
}
return dp[row][prv] = ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define task "tst"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
//freopen(task".out", "w", stdout);
}
cin>>n>>m;
for (ll i = 1;i <= n;i++)
for (ll j = 1;j <= m;j++) cin>>a[i][j];
for (ll i = 1;i <= n;i++)
for (ll j = 1;j <= m;j++){
aval[i][j][1] = chk(i,j,1);
aval[i][j][2] = chk(i,j,2);
}
//cout<<aval[3][2][2]; return 0;
for (ll i = 2;i <= n + m;i++){
memset(dp,-1,sizeof(dp)); dia = i;
ans += f(1,0);
}
cout<<ans;
}
Compilation message
dango_maker.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
1 | #pragma GCC optimization "O2"
|
dango_maker.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
2 | #pragma GCC optimization "unroll-loop"
|
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:53:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
460 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
460 KB |
Output is correct |
29 |
Correct |
1 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
460 KB |
Output is correct |
31 |
Correct |
1 ms |
460 KB |
Output is correct |
32 |
Correct |
1 ms |
460 KB |
Output is correct |
33 |
Correct |
1 ms |
460 KB |
Output is correct |
34 |
Correct |
1 ms |
460 KB |
Output is correct |
35 |
Correct |
1 ms |
460 KB |
Output is correct |
36 |
Correct |
1 ms |
460 KB |
Output is correct |
37 |
Correct |
1 ms |
460 KB |
Output is correct |
38 |
Correct |
1 ms |
460 KB |
Output is correct |
39 |
Correct |
1 ms |
460 KB |
Output is correct |
40 |
Correct |
1 ms |
460 KB |
Output is correct |
41 |
Correct |
1 ms |
460 KB |
Output is correct |
42 |
Correct |
1 ms |
460 KB |
Output is correct |
43 |
Correct |
1 ms |
460 KB |
Output is correct |
44 |
Correct |
1 ms |
460 KB |
Output is correct |
45 |
Correct |
1 ms |
460 KB |
Output is correct |
46 |
Correct |
1 ms |
460 KB |
Output is correct |
47 |
Correct |
1 ms |
460 KB |
Output is correct |
48 |
Correct |
1 ms |
460 KB |
Output is correct |
49 |
Correct |
1 ms |
460 KB |
Output is correct |
50 |
Correct |
1 ms |
460 KB |
Output is correct |
51 |
Correct |
1 ms |
460 KB |
Output is correct |
52 |
Correct |
1 ms |
460 KB |
Output is correct |
53 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
460 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
460 KB |
Output is correct |
29 |
Correct |
1 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
460 KB |
Output is correct |
31 |
Correct |
1 ms |
460 KB |
Output is correct |
32 |
Correct |
1 ms |
460 KB |
Output is correct |
33 |
Correct |
1 ms |
460 KB |
Output is correct |
34 |
Correct |
1 ms |
460 KB |
Output is correct |
35 |
Correct |
1 ms |
460 KB |
Output is correct |
36 |
Correct |
1 ms |
460 KB |
Output is correct |
37 |
Correct |
1 ms |
460 KB |
Output is correct |
38 |
Correct |
1 ms |
460 KB |
Output is correct |
39 |
Correct |
1 ms |
460 KB |
Output is correct |
40 |
Correct |
1 ms |
460 KB |
Output is correct |
41 |
Correct |
1 ms |
460 KB |
Output is correct |
42 |
Correct |
1 ms |
460 KB |
Output is correct |
43 |
Correct |
1 ms |
460 KB |
Output is correct |
44 |
Correct |
1 ms |
460 KB |
Output is correct |
45 |
Correct |
1 ms |
460 KB |
Output is correct |
46 |
Correct |
1 ms |
460 KB |
Output is correct |
47 |
Correct |
1 ms |
460 KB |
Output is correct |
48 |
Correct |
1 ms |
460 KB |
Output is correct |
49 |
Correct |
1 ms |
460 KB |
Output is correct |
50 |
Correct |
1 ms |
460 KB |
Output is correct |
51 |
Correct |
1 ms |
460 KB |
Output is correct |
52 |
Correct |
1 ms |
460 KB |
Output is correct |
53 |
Correct |
1 ms |
460 KB |
Output is correct |
54 |
Correct |
80 ms |
708 KB |
Output is correct |
55 |
Correct |
101 ms |
24652 KB |
Output is correct |
56 |
Correct |
86 ms |
784 KB |
Output is correct |
57 |
Correct |
43 ms |
16628 KB |
Output is correct |
58 |
Correct |
79 ms |
14508 KB |
Output is correct |
59 |
Correct |
685 ms |
74672 KB |
Output is correct |
60 |
Correct |
716 ms |
83440 KB |
Output is correct |
61 |
Correct |
720 ms |
83328 KB |
Output is correct |
62 |
Correct |
72 ms |
760 KB |
Output is correct |
63 |
Correct |
682 ms |
81628 KB |
Output is correct |
64 |
Correct |
704 ms |
83396 KB |
Output is correct |
65 |
Correct |
707 ms |
83392 KB |
Output is correct |
66 |
Correct |
694 ms |
83520 KB |
Output is correct |
67 |
Correct |
627 ms |
83428 KB |
Output is correct |
68 |
Correct |
620 ms |
83488 KB |
Output is correct |
69 |
Correct |
622 ms |
83400 KB |
Output is correct |
70 |
Correct |
77 ms |
15452 KB |
Output is correct |
71 |
Correct |
74 ms |
15512 KB |
Output is correct |
72 |
Correct |
73 ms |
15400 KB |
Output is correct |
73 |
Correct |
73 ms |
15416 KB |
Output is correct |
74 |
Correct |
74 ms |
15416 KB |
Output is correct |
75 |
Correct |
74 ms |
15428 KB |
Output is correct |
76 |
Correct |
75 ms |
15388 KB |
Output is correct |
77 |
Correct |
74 ms |
15428 KB |
Output is correct |
78 |
Correct |
74 ms |
15384 KB |
Output is correct |
79 |
Correct |
74 ms |
15376 KB |
Output is correct |
80 |
Correct |
73 ms |
15484 KB |
Output is correct |
81 |
Correct |
75 ms |
15476 KB |
Output is correct |
82 |
Correct |
72 ms |
15560 KB |
Output is correct |
83 |
Correct |
73 ms |
15428 KB |
Output is correct |
84 |
Correct |
75 ms |
15412 KB |
Output is correct |
85 |
Correct |
77 ms |
15416 KB |
Output is correct |
86 |
Correct |
77 ms |
15384 KB |
Output is correct |
87 |
Correct |
75 ms |
15488 KB |
Output is correct |
88 |
Correct |
74 ms |
15520 KB |
Output is correct |
89 |
Correct |
75 ms |
15476 KB |
Output is correct |
90 |
Correct |
72 ms |
15424 KB |
Output is correct |