#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 1000010
#define N 5010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
#define int long long
#define inf (int)1e18
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1LL << j))
#define onbit(i, j) (i | (1LL << j))
#define vi vector<int>
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
int f[2 * N][3], a[N][N], good[N][N];
int n, m;
bool down(int i, int j)
{
return a[i][j] == 0 and a[i + 1][j] == 1 and a[i + 2][j] == 2;
}
bool right(int i, int j)
{
return a[i][j] == 0 and a[i][j + 1] == 1 and a[i][j + 2] == 2;
}
main()
{
#define name "TASK"
if (fopen(name ".inp", "r"))
{
freopen(name ".inp", "r", stdin);
freopen(name ".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
fo(i, 1, n) fo(j, 1, m)
{
char t;
cin >> t;
if (t == 'R')
a[i][j] = 0;
if (t == 'G')
a[i][j] = 1;
if (t == 'W')
a[i][j] = 2;
}
fo(i, 1, n) fo(j, 1, m)
{
if (down(i, j))
good[i + 1][j] ^= 1;
if (right(i, j))
good[i][j + 1] ^= 2;
}
int ans = 0;
fo(sum, 2, n + m)
{
int res = 0;
bool st = 0;
fo(i, 1, n)
{
int j = sum - i;
if(j > m or i > sum) continue;
if (!st)
{
st = 1;
f[i][0] = f[i][1] = f[i][2] = 0;
if (good[i][j] & 1)
f[i][1] = 1;
if (good[i][j] & 2)
f[i][2] = 1;
maximize(res, max({f[i][0], f[i][1], f[i][2]}));
continue;
}
else
{
f[i][0] = max({f[i - 1][0], f[i - 1][1], f[i - 1][2]});
f[i][1] = f[i][2] = 0;
if (good[i][j] & 1)
f[i][1] = 1;
if(i > 1) f[i][1] += max(f[i - 1][1],f[i - 1][0]);
if (good[i][j] & 2)
f[i][2] = 1;
if(i > 1) f[i][2] += max(f[i - 1][2],f[i - 1][0]);
}
maximize(res, max({f[i][0], f[i][1], f[i][2]}));
}
ans += res;
}
cout << ans;
en;
}
Compilation message
dango_maker.cpp:52:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
52 | main()
| ^~~~
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:57:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | freopen(name ".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:58:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | freopen(name ".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
0 ms |
4444 KB |
Output is correct |
24 |
Correct |
0 ms |
4444 KB |
Output is correct |
25 |
Correct |
0 ms |
2396 KB |
Output is correct |
26 |
Correct |
0 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
4440 KB |
Output is correct |
28 |
Correct |
0 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
1 ms |
4444 KB |
Output is correct |
37 |
Correct |
1 ms |
4444 KB |
Output is correct |
38 |
Correct |
1 ms |
4444 KB |
Output is correct |
39 |
Correct |
1 ms |
4444 KB |
Output is correct |
40 |
Correct |
1 ms |
4444 KB |
Output is correct |
41 |
Correct |
1 ms |
4444 KB |
Output is correct |
42 |
Correct |
1 ms |
4444 KB |
Output is correct |
43 |
Correct |
0 ms |
4444 KB |
Output is correct |
44 |
Correct |
1 ms |
4444 KB |
Output is correct |
45 |
Correct |
1 ms |
4444 KB |
Output is correct |
46 |
Correct |
0 ms |
4444 KB |
Output is correct |
47 |
Correct |
0 ms |
4444 KB |
Output is correct |
48 |
Correct |
1 ms |
4444 KB |
Output is correct |
49 |
Correct |
1 ms |
4444 KB |
Output is correct |
50 |
Correct |
1 ms |
4444 KB |
Output is correct |
51 |
Correct |
1 ms |
4444 KB |
Output is correct |
52 |
Correct |
1 ms |
4444 KB |
Output is correct |
53 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
0 ms |
4444 KB |
Output is correct |
24 |
Correct |
0 ms |
4444 KB |
Output is correct |
25 |
Correct |
0 ms |
2396 KB |
Output is correct |
26 |
Correct |
0 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
4440 KB |
Output is correct |
28 |
Correct |
0 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
1 ms |
4444 KB |
Output is correct |
37 |
Correct |
1 ms |
4444 KB |
Output is correct |
38 |
Correct |
1 ms |
4444 KB |
Output is correct |
39 |
Correct |
1 ms |
4444 KB |
Output is correct |
40 |
Correct |
1 ms |
4444 KB |
Output is correct |
41 |
Correct |
1 ms |
4444 KB |
Output is correct |
42 |
Correct |
1 ms |
4444 KB |
Output is correct |
43 |
Correct |
0 ms |
4444 KB |
Output is correct |
44 |
Correct |
1 ms |
4444 KB |
Output is correct |
45 |
Correct |
1 ms |
4444 KB |
Output is correct |
46 |
Correct |
0 ms |
4444 KB |
Output is correct |
47 |
Correct |
0 ms |
4444 KB |
Output is correct |
48 |
Correct |
1 ms |
4444 KB |
Output is correct |
49 |
Correct |
1 ms |
4444 KB |
Output is correct |
50 |
Correct |
1 ms |
4444 KB |
Output is correct |
51 |
Correct |
1 ms |
4444 KB |
Output is correct |
52 |
Correct |
1 ms |
4444 KB |
Output is correct |
53 |
Correct |
1 ms |
4444 KB |
Output is correct |
54 |
Correct |
1 ms |
2392 KB |
Output is correct |
55 |
Correct |
19 ms |
114436 KB |
Output is correct |
56 |
Correct |
1 ms |
4444 KB |
Output is correct |
57 |
Correct |
18 ms |
113740 KB |
Output is correct |
58 |
Correct |
37 ms |
82524 KB |
Output is correct |
59 |
Correct |
325 ms |
198996 KB |
Output is correct |
60 |
Correct |
331 ms |
207868 KB |
Output is correct |
61 |
Correct |
332 ms |
208888 KB |
Output is correct |
62 |
Correct |
1 ms |
2392 KB |
Output is correct |
63 |
Correct |
330 ms |
205028 KB |
Output is correct |
64 |
Correct |
211 ms |
210016 KB |
Output is correct |
65 |
Correct |
204 ms |
210180 KB |
Output is correct |
66 |
Correct |
207 ms |
210184 KB |
Output is correct |
67 |
Correct |
190 ms |
155216 KB |
Output is correct |
68 |
Correct |
181 ms |
155352 KB |
Output is correct |
69 |
Correct |
196 ms |
162132 KB |
Output is correct |
70 |
Correct |
23 ms |
83548 KB |
Output is correct |
71 |
Correct |
23 ms |
83532 KB |
Output is correct |
72 |
Correct |
23 ms |
83548 KB |
Output is correct |
73 |
Correct |
24 ms |
83536 KB |
Output is correct |
74 |
Correct |
23 ms |
83548 KB |
Output is correct |
75 |
Correct |
23 ms |
83548 KB |
Output is correct |
76 |
Correct |
22 ms |
83548 KB |
Output is correct |
77 |
Correct |
23 ms |
83548 KB |
Output is correct |
78 |
Correct |
23 ms |
83524 KB |
Output is correct |
79 |
Correct |
23 ms |
83548 KB |
Output is correct |
80 |
Correct |
24 ms |
83548 KB |
Output is correct |
81 |
Correct |
23 ms |
83540 KB |
Output is correct |
82 |
Correct |
24 ms |
83532 KB |
Output is correct |
83 |
Correct |
23 ms |
83548 KB |
Output is correct |
84 |
Correct |
22 ms |
83548 KB |
Output is correct |
85 |
Correct |
23 ms |
83548 KB |
Output is correct |
86 |
Correct |
25 ms |
83600 KB |
Output is correct |
87 |
Correct |
21 ms |
83544 KB |
Output is correct |
88 |
Correct |
22 ms |
83536 KB |
Output is correct |
89 |
Correct |
22 ms |
83580 KB |
Output is correct |
90 |
Correct |
24 ms |
83536 KB |
Output is correct |