#include <bits/stdc++.h>
#define loop(i,a,b) for(int i = (a); i < (b); i ++)
#define pb push_back
#define ins insert
#define pii pair<int,int>
#define ff first
#define ss second
#define op(x) cerr << #x << " = " << x << endl;
#define opa(x) cerr << #x << " = " << x << ", ";
#define ops(x) cerr << x;
#define entr cerr << endl;
#define spac cerr << ' ';
#define STL(x) cerr << #x << " : "; for(auto &qwe:x) cerr << qwe << ' '; cerr << endl;
#define ARR(x, nnn) cerr << #x << " : "; loop(qwe,0,nnn) cerr << x[qwe] << ' '; cerr << endl;
#define BAE(x) x.begin(), x.end()
#define unilize(x) x.resize(unique(BAE(x)) - x.begin())
#define unisort(x) sort(BAE(x)); unilize(x);
using namespace std;
typedef long long ll;
const int mxn = 3010;
char c[mxn][mxn];
bool canr[mxn][mxn], cand[mxn][mxn];
int dpr[mxn][mxn], dpd[mxn][mxn], dp[mxn][mxn];
int n, m;
inline bool check(int i, int j){
return i >= 0 && i < n && j >= 0 && j < m;
}
int main(){
// freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> m;
loop(i,0,n){
loop(j,0,m){
cin >> c[i][j];
}
}
int now = 0;
loop(i,0,n){
loop(j,0,m){
if(check(i, j - 1))
if(c[i][j-1] == 'R' && c[i][j] == 'G' && c[i][j+1] == 'W'){
canr[i][j] = true;
}
if(check(i-1, j))
if(c[i-1][j] == 'R' && c[i][j] == 'G' && c[i+1][j] == 'W'){
cand[i][j] = true;
}
}
}
int ans = 0;
loop(k,0,n){
for(int i = k, j = 0; i >= 0 && j < m; i --, j++){
if(canr[i][j]){
if(check(i + 1, j - 1)){
dpr[i][j] = max(dpr[i+1][j-1], dp[i+1][j-1]);
}
dpr[i][j]++;
}
if(cand[i][j]){
if(check(i + 1, j - 1)){
dpd[i][j] = max(dpd[i+1][j-1], dp[i+1][j-1]);
}
dpd[i][j]++;
}
if(check(i + 1, j - 1)){
dp[i][j] = max({dpd[i+1][j-1], dp[i+1][j-1], dpr[i+1][j-1]});
}
}
}
loop(k,1,m){
for(int i = n - 1, j = k; i >= 0 && j < m; i --, j++){
if(canr[i][j]){
if(check(i + 1, j - 1)){
dpr[i][j] = max(dpr[i+1][j-1], dp[i+1][j-1]);
}
dpr[i][j]++;
}
if(cand[i][j]){
if(check(i + 1, j - 1)){
dpd[i][j] = max(dpd[i+1][j-1], dp[i+1][j-1]);
}
dpd[i][j]++;
}
if(check(i + 1, j - 1)){
dp[i][j] = max({dpd[i+1][j-1], dp[i+1][j-1], dpr[i+1][j-1]});
}
}
}
loop(j,0,m){
ans += max({dp[0][j], dpr[0][j], dpd[0][j]});
}
loop(i,1,n){
ans += max({dp[i][m-1], dpr[i][m-1], dpd[i][m-1]});
}
// loop(i,0,n){
// loop(j,0,m){
// ops("(") ops(dp[i][j]) ops(", ")
// ops(dpd[i][j]) ops(", ")
// ops(dpr[i][j]) ops(") ")
// } entr
// }
cout << ans << '\n';
}
Compilation message
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:39:9: warning: unused variable 'now' [-Wunused-variable]
39 | int now = 0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 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 |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6744 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4556 KB |
Output is correct |
16 |
Correct |
1 ms |
4440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 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 |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6744 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4556 KB |
Output is correct |
16 |
Correct |
1 ms |
4440 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6488 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 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 |
6492 KB |
Output is correct |
34 |
Correct |
1 ms |
6492 KB |
Output is correct |
35 |
Correct |
1 ms |
6492 KB |
Output is correct |
36 |
Correct |
1 ms |
6492 KB |
Output is correct |
37 |
Correct |
1 ms |
6492 KB |
Output is correct |
38 |
Correct |
1 ms |
6492 KB |
Output is correct |
39 |
Correct |
1 ms |
6900 KB |
Output is correct |
40 |
Correct |
1 ms |
6492 KB |
Output is correct |
41 |
Correct |
1 ms |
6488 KB |
Output is correct |
42 |
Correct |
1 ms |
6492 KB |
Output is correct |
43 |
Correct |
1 ms |
6492 KB |
Output is correct |
44 |
Correct |
1 ms |
6492 KB |
Output is correct |
45 |
Correct |
1 ms |
6492 KB |
Output is correct |
46 |
Correct |
1 ms |
6492 KB |
Output is correct |
47 |
Correct |
1 ms |
6492 KB |
Output is correct |
48 |
Correct |
1 ms |
6492 KB |
Output is correct |
49 |
Correct |
1 ms |
6492 KB |
Output is correct |
50 |
Correct |
1 ms |
6500 KB |
Output is correct |
51 |
Correct |
1 ms |
6500 KB |
Output is correct |
52 |
Correct |
1 ms |
6492 KB |
Output is correct |
53 |
Correct |
1 ms |
6500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 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 |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6744 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4556 KB |
Output is correct |
16 |
Correct |
1 ms |
4440 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6488 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 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 |
6492 KB |
Output is correct |
34 |
Correct |
1 ms |
6492 KB |
Output is correct |
35 |
Correct |
1 ms |
6492 KB |
Output is correct |
36 |
Correct |
1 ms |
6492 KB |
Output is correct |
37 |
Correct |
1 ms |
6492 KB |
Output is correct |
38 |
Correct |
1 ms |
6492 KB |
Output is correct |
39 |
Correct |
1 ms |
6900 KB |
Output is correct |
40 |
Correct |
1 ms |
6492 KB |
Output is correct |
41 |
Correct |
1 ms |
6488 KB |
Output is correct |
42 |
Correct |
1 ms |
6492 KB |
Output is correct |
43 |
Correct |
1 ms |
6492 KB |
Output is correct |
44 |
Correct |
1 ms |
6492 KB |
Output is correct |
45 |
Correct |
1 ms |
6492 KB |
Output is correct |
46 |
Correct |
1 ms |
6492 KB |
Output is correct |
47 |
Correct |
1 ms |
6492 KB |
Output is correct |
48 |
Correct |
1 ms |
6492 KB |
Output is correct |
49 |
Correct |
1 ms |
6492 KB |
Output is correct |
50 |
Correct |
1 ms |
6500 KB |
Output is correct |
51 |
Correct |
1 ms |
6500 KB |
Output is correct |
52 |
Correct |
1 ms |
6492 KB |
Output is correct |
53 |
Correct |
1 ms |
6500 KB |
Output is correct |
54 |
Correct |
1 ms |
4452 KB |
Output is correct |
55 |
Correct |
7 ms |
22888 KB |
Output is correct |
56 |
Correct |
1 ms |
6760 KB |
Output is correct |
57 |
Correct |
12 ms |
41064 KB |
Output is correct |
58 |
Correct |
54 ms |
38984 KB |
Output is correct |
59 |
Correct |
614 ms |
141920 KB |
Output is correct |
60 |
Correct |
596 ms |
142008 KB |
Output is correct |
61 |
Correct |
562 ms |
142032 KB |
Output is correct |
62 |
Correct |
1 ms |
4444 KB |
Output is correct |
63 |
Correct |
564 ms |
141508 KB |
Output is correct |
64 |
Correct |
497 ms |
141904 KB |
Output is correct |
65 |
Correct |
504 ms |
142044 KB |
Output is correct |
66 |
Correct |
489 ms |
141768 KB |
Output is correct |
67 |
Correct |
335 ms |
82372 KB |
Output is correct |
68 |
Correct |
366 ms |
88772 KB |
Output is correct |
69 |
Correct |
414 ms |
98112 KB |
Output is correct |
70 |
Correct |
47 ms |
39372 KB |
Output is correct |
71 |
Correct |
44 ms |
39508 KB |
Output is correct |
72 |
Correct |
51 ms |
39444 KB |
Output is correct |
73 |
Correct |
50 ms |
39284 KB |
Output is correct |
74 |
Correct |
45 ms |
39504 KB |
Output is correct |
75 |
Correct |
51 ms |
39508 KB |
Output is correct |
76 |
Correct |
50 ms |
39508 KB |
Output is correct |
77 |
Correct |
51 ms |
39480 KB |
Output is correct |
78 |
Correct |
51 ms |
39508 KB |
Output is correct |
79 |
Correct |
46 ms |
39504 KB |
Output is correct |
80 |
Correct |
49 ms |
39516 KB |
Output is correct |
81 |
Correct |
49 ms |
39340 KB |
Output is correct |
82 |
Correct |
53 ms |
39668 KB |
Output is correct |
83 |
Correct |
44 ms |
39364 KB |
Output is correct |
84 |
Correct |
48 ms |
39420 KB |
Output is correct |
85 |
Correct |
47 ms |
39508 KB |
Output is correct |
86 |
Correct |
54 ms |
39504 KB |
Output is correct |
87 |
Correct |
56 ms |
39504 KB |
Output is correct |
88 |
Correct |
51 ms |
39488 KB |
Output is correct |
89 |
Correct |
51 ms |
39492 KB |
Output is correct |
90 |
Correct |
50 ms |
39508 KB |
Output is correct |