#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
#define __builtin_popcount __builtin_popcountll
using ll=long long; using ld=long double;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const ld pi=acos(0)*2;
template <typename T> inline void read(T &x){char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){nega=1; c=getchar();} x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10); putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){ putchar('-'); x=-x;} writep(x);}
template <typename T> inline void writeln(T x){write(x); putchar('\n');}
#define taskname "Dango"
int n, m;
string s[3000];
int f[6000][3];
int dp(vector <int> &x){
// reverse(x.begin(), x.end());
// for(int a: x) cerr<<a<<' ';
// cerr<<'\n';
FFOR(i, 0, x.size()) FFOR(j, 0, 3) f[i][j]=0;
int ans=0;
FFOR(i, 0, x.size()){
if(x[i]&2){
f[i][2]=1;
if(i>0) f[i][2]=max(f[i][2], max(f[i-1][0], f[i-1][2])+1);
}
if(x[i]&1){
f[i][1]=1;
if(i>0) f[i][1]=max(f[i][1], max(f[i-1][0], f[i-1][1])+1);
}
if(i>0) f[i][0]=max(f[i][0], f[i-1][0]);
if(i>0) f[i][0]=max(f[i][0], f[i-1][1]);
if(i>0) f[i][0]=max(f[i][0], f[i-1][2]);
ans=max(ans, f[i][0]);
ans=max(ans, f[i][1]);
ans=max(ans, f[i][2]);
}
return ans;
}
bool good_right(int i, int j){
if(i<0) return 0;
if(j<0) return 0;
if(j+2>=m) return 0;
return (s[i][j]=='R')&&(s[i][j+1]=='G')&&(s[i][j+2]=='W');
}
bool good_down(int i, int j){
if(i<0) return 0;
if(j<0) return 0;
if(i+2>=n) return 0;
return (s[i][j]=='R')&&(s[i+1][j]=='G')&&(s[i+2][j]=='W');
}
int cnt[3000][3000];
int main(){
#ifdef Aria
if(fopen(taskname".in", "r"))
freopen(taskname".in", "r", stdin);
#endif // Aria
cin>>n>>m;
FFOR(i, 0, n) cin>>s[i];
int ans=0;
for(int i=0, j=0; (j<m); j+=((i+1)==n), i=min(n-1, i+1)){
vector <int> all;
FFOR(k, 0, 1e9){
if(i-k<0) break;
if(j+k>=m) break;
cnt[i-k][j+k]++;
int d=0;
if(good_down(i-k-1, j+k)) d^=1;
if(good_right(i-k, j+k-1)) d^=2;
// if(d) assert(s[i][j]=='G');
all.pb(d);
}
ans+=dp(all);
}
// FFOR(i, 0, n) FFOR(j, 0, m) cerr<<cnt[i][j]<<" \n"[j+1==m];
writeln(ans);
}
Compilation message
dango_maker.cpp: In function 'int dp(std::vector<int>&)':
dango_maker.cpp:4:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
^
dango_maker.cpp:27:5: note: in expansion of macro 'FFOR'
FFOR(i, 0, x.size()) FFOR(j, 0, 3) f[i][j]=0;
^~~~
dango_maker.cpp:4:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
^
dango_maker.cpp:29:5: note: in expansion of macro 'FFOR'
FFOR(i, 0, x.size()){
^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
512 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
512 KB |
Output is correct |
16 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
512 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
512 KB |
Output is correct |
16 |
Correct |
2 ms |
512 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
512 KB |
Output is correct |
19 |
Correct |
2 ms |
512 KB |
Output is correct |
20 |
Correct |
2 ms |
432 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
512 KB |
Output is correct |
23 |
Correct |
2 ms |
512 KB |
Output is correct |
24 |
Correct |
2 ms |
512 KB |
Output is correct |
25 |
Correct |
2 ms |
512 KB |
Output is correct |
26 |
Correct |
2 ms |
256 KB |
Output is correct |
27 |
Correct |
2 ms |
512 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
4 ms |
384 KB |
Output is correct |
30 |
Correct |
2 ms |
384 KB |
Output is correct |
31 |
Correct |
2 ms |
384 KB |
Output is correct |
32 |
Correct |
2 ms |
384 KB |
Output is correct |
33 |
Correct |
2 ms |
384 KB |
Output is correct |
34 |
Correct |
2 ms |
384 KB |
Output is correct |
35 |
Correct |
2 ms |
512 KB |
Output is correct |
36 |
Correct |
2 ms |
512 KB |
Output is correct |
37 |
Correct |
2 ms |
512 KB |
Output is correct |
38 |
Correct |
2 ms |
512 KB |
Output is correct |
39 |
Correct |
2 ms |
512 KB |
Output is correct |
40 |
Correct |
2 ms |
512 KB |
Output is correct |
41 |
Correct |
3 ms |
512 KB |
Output is correct |
42 |
Correct |
2 ms |
512 KB |
Output is correct |
43 |
Correct |
2 ms |
512 KB |
Output is correct |
44 |
Correct |
2 ms |
384 KB |
Output is correct |
45 |
Correct |
2 ms |
512 KB |
Output is correct |
46 |
Correct |
2 ms |
512 KB |
Output is correct |
47 |
Correct |
2 ms |
512 KB |
Output is correct |
48 |
Correct |
2 ms |
512 KB |
Output is correct |
49 |
Correct |
4 ms |
512 KB |
Output is correct |
50 |
Correct |
2 ms |
512 KB |
Output is correct |
51 |
Correct |
2 ms |
512 KB |
Output is correct |
52 |
Correct |
2 ms |
512 KB |
Output is correct |
53 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
512 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
512 KB |
Output is correct |
16 |
Correct |
2 ms |
512 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
512 KB |
Output is correct |
19 |
Correct |
2 ms |
512 KB |
Output is correct |
20 |
Correct |
2 ms |
432 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
512 KB |
Output is correct |
23 |
Correct |
2 ms |
512 KB |
Output is correct |
24 |
Correct |
2 ms |
512 KB |
Output is correct |
25 |
Correct |
2 ms |
512 KB |
Output is correct |
26 |
Correct |
2 ms |
256 KB |
Output is correct |
27 |
Correct |
2 ms |
512 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
4 ms |
384 KB |
Output is correct |
30 |
Correct |
2 ms |
384 KB |
Output is correct |
31 |
Correct |
2 ms |
384 KB |
Output is correct |
32 |
Correct |
2 ms |
384 KB |
Output is correct |
33 |
Correct |
2 ms |
384 KB |
Output is correct |
34 |
Correct |
2 ms |
384 KB |
Output is correct |
35 |
Correct |
2 ms |
512 KB |
Output is correct |
36 |
Correct |
2 ms |
512 KB |
Output is correct |
37 |
Correct |
2 ms |
512 KB |
Output is correct |
38 |
Correct |
2 ms |
512 KB |
Output is correct |
39 |
Correct |
2 ms |
512 KB |
Output is correct |
40 |
Correct |
2 ms |
512 KB |
Output is correct |
41 |
Correct |
3 ms |
512 KB |
Output is correct |
42 |
Correct |
2 ms |
512 KB |
Output is correct |
43 |
Correct |
2 ms |
512 KB |
Output is correct |
44 |
Correct |
2 ms |
384 KB |
Output is correct |
45 |
Correct |
2 ms |
512 KB |
Output is correct |
46 |
Correct |
2 ms |
512 KB |
Output is correct |
47 |
Correct |
2 ms |
512 KB |
Output is correct |
48 |
Correct |
2 ms |
512 KB |
Output is correct |
49 |
Correct |
4 ms |
512 KB |
Output is correct |
50 |
Correct |
2 ms |
512 KB |
Output is correct |
51 |
Correct |
2 ms |
512 KB |
Output is correct |
52 |
Correct |
2 ms |
512 KB |
Output is correct |
53 |
Correct |
2 ms |
512 KB |
Output is correct |
54 |
Correct |
2 ms |
384 KB |
Output is correct |
55 |
Correct |
11 ms |
12544 KB |
Output is correct |
56 |
Correct |
3 ms |
512 KB |
Output is correct |
57 |
Correct |
10 ms |
8448 KB |
Output is correct |
58 |
Correct |
69 ms |
11256 KB |
Output is correct |
59 |
Correct |
732 ms |
55940 KB |
Output is correct |
60 |
Correct |
705 ms |
56004 KB |
Output is correct |
61 |
Correct |
690 ms |
56056 KB |
Output is correct |
62 |
Correct |
3 ms |
512 KB |
Output is correct |
63 |
Correct |
638 ms |
55544 KB |
Output is correct |
64 |
Correct |
592 ms |
55976 KB |
Output is correct |
65 |
Correct |
606 ms |
56152 KB |
Output is correct |
66 |
Correct |
596 ms |
56056 KB |
Output is correct |
67 |
Correct |
597 ms |
56056 KB |
Output is correct |
68 |
Correct |
607 ms |
55996 KB |
Output is correct |
69 |
Correct |
628 ms |
56048 KB |
Output is correct |
70 |
Correct |
62 ms |
11256 KB |
Output is correct |
71 |
Correct |
63 ms |
11252 KB |
Output is correct |
72 |
Correct |
62 ms |
11256 KB |
Output is correct |
73 |
Correct |
61 ms |
11180 KB |
Output is correct |
74 |
Correct |
63 ms |
11232 KB |
Output is correct |
75 |
Correct |
59 ms |
11260 KB |
Output is correct |
76 |
Correct |
59 ms |
11256 KB |
Output is correct |
77 |
Correct |
59 ms |
11256 KB |
Output is correct |
78 |
Correct |
58 ms |
11256 KB |
Output is correct |
79 |
Correct |
63 ms |
11416 KB |
Output is correct |
80 |
Correct |
60 ms |
11256 KB |
Output is correct |
81 |
Correct |
63 ms |
11256 KB |
Output is correct |
82 |
Correct |
61 ms |
11256 KB |
Output is correct |
83 |
Correct |
59 ms |
11256 KB |
Output is correct |
84 |
Correct |
58 ms |
11256 KB |
Output is correct |
85 |
Correct |
58 ms |
11256 KB |
Output is correct |
86 |
Correct |
59 ms |
11256 KB |
Output is correct |
87 |
Correct |
57 ms |
11256 KB |
Output is correct |
88 |
Correct |
57 ms |
11256 KB |
Output is correct |
89 |
Correct |
57 ms |
11256 KB |
Output is correct |
90 |
Correct |
57 ms |
11256 KB |
Output is correct |