#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <deque>
#include <map>
#include <set>
#include <complex>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <random>
#define ft first
#define sc second
#define pb push_back
#define len(v) (int)v.size()
// #define int ll
using namespace std;
typedef long long ll;
signed main() {
#ifdef PC
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, cnt = 0, ans = 0;
cin >> n >> m;
vector<vector<char>> mat(n, vector<char> (m));
vector<vector<bool>> hor(n, vector<bool> (m, 0));
vector<vector<bool>> ver(n, vector<bool> (m, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> mat[i][j];
}
}
for (int i = 0; i < n - 2; i++) {
for (int j = 0; j < m; j++) {
if(!(mat[i][j] == 'R' && mat[i + 1][j] == 'G' && mat[i + 2][j] == 'W'))
continue;
ver[i][j] = 1;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m - 2; j++) {
if(!(mat[i][j] == 'R' && mat[i][j + 1] == 'G' && mat[i][j + 2] == 'W'))
continue;
hor[i][j] = 1;
}
}
for (int nn = 0; nn < n + m; nn++) {
int i1, j1;
if(nn < n) {
i1 = nn, j1 = 0;
}
else {
i1 = n - 1, j1 = nn - i1;
}
vector<pair<int, int>> now;
while(i1 >= 0 && j1 < m) {
// cout << "(" << i1 << ", " << j1 << ") ";
now.pb({ver[i1][j1], hor[i1][j1]});
i1--, j1++;
}
// cout << endl;
reverse(now.begin(), now.end());
int nr = len(now);
vector<vector<int>> dp(nr + 1, vector<int> (3, 0));
for (int i = 0; i < nr; i++) {
for (int j = 0; j < 3; j++) {
dp[i + 1][j] = dp[i][max(j - 1, 0)];
if(now[i].sc)
dp[i + 1][j] = max(dp[i + 1][j], 1 + dp[i][2]);
if(j == 0 && now[i].ft)
dp[i + 1][j] = max(dp[i + 1][j], 1 + dp[i][0]);
}
}
ans += dp[nr][0];
}
cout << ans << endl;
}
Compilation message
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:32:12: warning: unused variable 'cnt' [-Wunused-variable]
int n, m, cnt = 0, ans = 0;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
4 ms |
384 KB |
Output is correct |
26 |
Correct |
4 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
4 ms |
384 KB |
Output is correct |
32 |
Correct |
4 ms |
384 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
4 ms |
384 KB |
Output is correct |
36 |
Correct |
5 ms |
384 KB |
Output is correct |
37 |
Correct |
4 ms |
384 KB |
Output is correct |
38 |
Correct |
5 ms |
384 KB |
Output is correct |
39 |
Correct |
4 ms |
384 KB |
Output is correct |
40 |
Correct |
5 ms |
384 KB |
Output is correct |
41 |
Correct |
5 ms |
384 KB |
Output is correct |
42 |
Correct |
5 ms |
384 KB |
Output is correct |
43 |
Correct |
5 ms |
384 KB |
Output is correct |
44 |
Correct |
5 ms |
384 KB |
Output is correct |
45 |
Correct |
5 ms |
384 KB |
Output is correct |
46 |
Correct |
5 ms |
384 KB |
Output is correct |
47 |
Correct |
5 ms |
384 KB |
Output is correct |
48 |
Correct |
5 ms |
384 KB |
Output is correct |
49 |
Correct |
5 ms |
384 KB |
Output is correct |
50 |
Correct |
5 ms |
384 KB |
Output is correct |
51 |
Correct |
5 ms |
384 KB |
Output is correct |
52 |
Correct |
5 ms |
384 KB |
Output is correct |
53 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
4 ms |
384 KB |
Output is correct |
26 |
Correct |
4 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
4 ms |
384 KB |
Output is correct |
32 |
Correct |
4 ms |
384 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
4 ms |
384 KB |
Output is correct |
36 |
Correct |
5 ms |
384 KB |
Output is correct |
37 |
Correct |
4 ms |
384 KB |
Output is correct |
38 |
Correct |
5 ms |
384 KB |
Output is correct |
39 |
Correct |
4 ms |
384 KB |
Output is correct |
40 |
Correct |
5 ms |
384 KB |
Output is correct |
41 |
Correct |
5 ms |
384 KB |
Output is correct |
42 |
Correct |
5 ms |
384 KB |
Output is correct |
43 |
Correct |
5 ms |
384 KB |
Output is correct |
44 |
Correct |
5 ms |
384 KB |
Output is correct |
45 |
Correct |
5 ms |
384 KB |
Output is correct |
46 |
Correct |
5 ms |
384 KB |
Output is correct |
47 |
Correct |
5 ms |
384 KB |
Output is correct |
48 |
Correct |
5 ms |
384 KB |
Output is correct |
49 |
Correct |
5 ms |
384 KB |
Output is correct |
50 |
Correct |
5 ms |
384 KB |
Output is correct |
51 |
Correct |
5 ms |
384 KB |
Output is correct |
52 |
Correct |
5 ms |
384 KB |
Output is correct |
53 |
Correct |
5 ms |
384 KB |
Output is correct |
54 |
Correct |
5 ms |
384 KB |
Output is correct |
55 |
Correct |
6 ms |
896 KB |
Output is correct |
56 |
Correct |
7 ms |
384 KB |
Output is correct |
57 |
Correct |
7 ms |
768 KB |
Output is correct |
58 |
Correct |
105 ms |
2808 KB |
Output is correct |
59 |
Correct |
850 ms |
20780 KB |
Output is correct |
60 |
Correct |
856 ms |
20888 KB |
Output is correct |
61 |
Correct |
863 ms |
20796 KB |
Output is correct |
62 |
Correct |
5 ms |
384 KB |
Output is correct |
63 |
Correct |
825 ms |
20176 KB |
Output is correct |
64 |
Correct |
765 ms |
20976 KB |
Output is correct |
65 |
Correct |
758 ms |
20856 KB |
Output is correct |
66 |
Correct |
762 ms |
20976 KB |
Output is correct |
67 |
Correct |
751 ms |
20880 KB |
Output is correct |
68 |
Correct |
763 ms |
21096 KB |
Output is correct |
69 |
Correct |
760 ms |
21000 KB |
Output is correct |
70 |
Correct |
86 ms |
2688 KB |
Output is correct |
71 |
Correct |
86 ms |
2688 KB |
Output is correct |
72 |
Correct |
86 ms |
2688 KB |
Output is correct |
73 |
Correct |
85 ms |
2688 KB |
Output is correct |
74 |
Correct |
85 ms |
2816 KB |
Output is correct |
75 |
Correct |
89 ms |
2808 KB |
Output is correct |
76 |
Correct |
85 ms |
2688 KB |
Output is correct |
77 |
Correct |
86 ms |
2688 KB |
Output is correct |
78 |
Correct |
86 ms |
2688 KB |
Output is correct |
79 |
Correct |
84 ms |
2688 KB |
Output is correct |
80 |
Correct |
85 ms |
2688 KB |
Output is correct |
81 |
Correct |
87 ms |
2688 KB |
Output is correct |
82 |
Correct |
86 ms |
2808 KB |
Output is correct |
83 |
Correct |
90 ms |
2784 KB |
Output is correct |
84 |
Correct |
87 ms |
2808 KB |
Output is correct |
85 |
Correct |
92 ms |
2688 KB |
Output is correct |
86 |
Correct |
87 ms |
2688 KB |
Output is correct |
87 |
Correct |
87 ms |
2688 KB |
Output is correct |
88 |
Correct |
85 ms |
2688 KB |
Output is correct |
89 |
Correct |
84 ms |
2808 KB |
Output is correct |
90 |
Correct |
85 ms |
2688 KB |
Output is correct |