#include<bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
const int maxn=3005;
int all[maxn][maxn],n,m,mainres=0,row[maxn][maxn],cal[maxn][maxn];
vector<pair<int,int>>asabnadaram[maxn*2];
struct fdp{
int r,c;
fdp(){
r=c=0;
}
};
void vorod(){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
char c;
cin>>c;
if(c=='R'){
all[i][j]=1;
}else if(c=='G'){
all[i][j]=2;
}else{
all[i][j]=3;
}
//cin>>all[i][j];
}
}
}
void pre(){
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(all[i][j]==1&&all[i][j+1]==2&&all[i][j+2]==3){
row[i][j]=1;
}
if(all[i][j]==1&&all[i+1][j]==2&&all[i+2][j]==3){
cal[i][j]=1;
}
}
}
}
vector<fdp>dp(maxn+6);
void calres(vector<pair<int,int>>&v){
for(int i=4;i<v.size();i++){
if(v[i].first==0){
dp[i].r=max(dp[i-1].r,dp[i-1].c);
}else{
dp[i].r=max(dp[i-1].r,dp[i-1].c)+1;
}
dp[i].c=max(dp[i-1].c,max(dp[i-2].c,max(dp[i-3].r,dp[i-3].c)));
if(v[i].second){
dp[i].c++;
}
}
mainres+=max(dp[(int)v.size()-1].c,dp[(int)v.size()-1].r);
}
void solve(){
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
asabnadaram[i+j].push_back(make_pair(row[i][j],cal[i][j]));
}
}
for(int i=0;i<maxn*2;i++){
asabnadaram[i].push_back(make_pair(0,0));
asabnadaram[i].push_back(make_pair(0,0));
asabnadaram[i].push_back(make_pair(0,0));
asabnadaram[i].push_back(make_pair(0,0));
reverse(asabnadaram[i].begin(),asabnadaram[i].end());
}
for(int i=0;i<maxn*2;i++){
calres(asabnadaram[i]);
}
}
void khor(){
cout<<mainres<<"\n";
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("inp.txt","r",stdin);
vorod();
pre();
solve();
khor();
}
Compilation message
dango_maker.cpp: In function 'void calres(std::vector<std::pair<int, int> >&)':
dango_maker.cpp:49:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(int i=4;i<v.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2904 KB |
Output is correct |
2 |
Correct |
1 ms |
2908 KB |
Output is correct |
3 |
Correct |
1 ms |
2908 KB |
Output is correct |
4 |
Correct |
1 ms |
2908 KB |
Output is correct |
5 |
Correct |
2 ms |
2908 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
1 ms |
4956 KB |
Output is correct |
10 |
Correct |
1 ms |
2908 KB |
Output is correct |
11 |
Correct |
1 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
4956 KB |
Output is correct |
13 |
Correct |
1 ms |
4956 KB |
Output is correct |
14 |
Correct |
2 ms |
2848 KB |
Output is correct |
15 |
Correct |
1 ms |
2904 KB |
Output is correct |
16 |
Correct |
1 ms |
2904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2904 KB |
Output is correct |
2 |
Correct |
1 ms |
2908 KB |
Output is correct |
3 |
Correct |
1 ms |
2908 KB |
Output is correct |
4 |
Correct |
1 ms |
2908 KB |
Output is correct |
5 |
Correct |
2 ms |
2908 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
1 ms |
4956 KB |
Output is correct |
10 |
Correct |
1 ms |
2908 KB |
Output is correct |
11 |
Correct |
1 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
4956 KB |
Output is correct |
13 |
Correct |
1 ms |
4956 KB |
Output is correct |
14 |
Correct |
2 ms |
2848 KB |
Output is correct |
15 |
Correct |
1 ms |
2904 KB |
Output is correct |
16 |
Correct |
1 ms |
2904 KB |
Output is correct |
17 |
Correct |
2 ms |
7004 KB |
Output is correct |
18 |
Correct |
1 ms |
7004 KB |
Output is correct |
19 |
Correct |
2 ms |
6852 KB |
Output is correct |
20 |
Correct |
2 ms |
7004 KB |
Output is correct |
21 |
Correct |
2 ms |
7004 KB |
Output is correct |
22 |
Correct |
1 ms |
7004 KB |
Output is correct |
23 |
Correct |
2 ms |
7004 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
1 ms |
2908 KB |
Output is correct |
26 |
Correct |
1 ms |
2904 KB |
Output is correct |
27 |
Correct |
2 ms |
7000 KB |
Output is correct |
28 |
Correct |
1 ms |
7004 KB |
Output is correct |
29 |
Correct |
2 ms |
7004 KB |
Output is correct |
30 |
Correct |
2 ms |
4956 KB |
Output is correct |
31 |
Correct |
1 ms |
4956 KB |
Output is correct |
32 |
Correct |
3 ms |
4952 KB |
Output is correct |
33 |
Correct |
2 ms |
7004 KB |
Output is correct |
34 |
Correct |
2 ms |
7004 KB |
Output is correct |
35 |
Correct |
2 ms |
7004 KB |
Output is correct |
36 |
Correct |
2 ms |
7004 KB |
Output is correct |
37 |
Correct |
2 ms |
7004 KB |
Output is correct |
38 |
Correct |
2 ms |
7004 KB |
Output is correct |
39 |
Correct |
2 ms |
7004 KB |
Output is correct |
40 |
Correct |
2 ms |
7004 KB |
Output is correct |
41 |
Correct |
3 ms |
7004 KB |
Output is correct |
42 |
Correct |
2 ms |
7000 KB |
Output is correct |
43 |
Correct |
2 ms |
7076 KB |
Output is correct |
44 |
Correct |
2 ms |
7004 KB |
Output is correct |
45 |
Correct |
2 ms |
7004 KB |
Output is correct |
46 |
Correct |
4 ms |
7004 KB |
Output is correct |
47 |
Correct |
2 ms |
7000 KB |
Output is correct |
48 |
Correct |
2 ms |
7256 KB |
Output is correct |
49 |
Correct |
2 ms |
7256 KB |
Output is correct |
50 |
Correct |
2 ms |
7004 KB |
Output is correct |
51 |
Correct |
2 ms |
7004 KB |
Output is correct |
52 |
Correct |
2 ms |
7044 KB |
Output is correct |
53 |
Correct |
5 ms |
7004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2904 KB |
Output is correct |
2 |
Correct |
1 ms |
2908 KB |
Output is correct |
3 |
Correct |
1 ms |
2908 KB |
Output is correct |
4 |
Correct |
1 ms |
2908 KB |
Output is correct |
5 |
Correct |
2 ms |
2908 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
1 ms |
4956 KB |
Output is correct |
10 |
Correct |
1 ms |
2908 KB |
Output is correct |
11 |
Correct |
1 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
4956 KB |
Output is correct |
13 |
Correct |
1 ms |
4956 KB |
Output is correct |
14 |
Correct |
2 ms |
2848 KB |
Output is correct |
15 |
Correct |
1 ms |
2904 KB |
Output is correct |
16 |
Correct |
1 ms |
2904 KB |
Output is correct |
17 |
Correct |
2 ms |
7004 KB |
Output is correct |
18 |
Correct |
1 ms |
7004 KB |
Output is correct |
19 |
Correct |
2 ms |
6852 KB |
Output is correct |
20 |
Correct |
2 ms |
7004 KB |
Output is correct |
21 |
Correct |
2 ms |
7004 KB |
Output is correct |
22 |
Correct |
1 ms |
7004 KB |
Output is correct |
23 |
Correct |
2 ms |
7004 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
1 ms |
2908 KB |
Output is correct |
26 |
Correct |
1 ms |
2904 KB |
Output is correct |
27 |
Correct |
2 ms |
7000 KB |
Output is correct |
28 |
Correct |
1 ms |
7004 KB |
Output is correct |
29 |
Correct |
2 ms |
7004 KB |
Output is correct |
30 |
Correct |
2 ms |
4956 KB |
Output is correct |
31 |
Correct |
1 ms |
4956 KB |
Output is correct |
32 |
Correct |
3 ms |
4952 KB |
Output is correct |
33 |
Correct |
2 ms |
7004 KB |
Output is correct |
34 |
Correct |
2 ms |
7004 KB |
Output is correct |
35 |
Correct |
2 ms |
7004 KB |
Output is correct |
36 |
Correct |
2 ms |
7004 KB |
Output is correct |
37 |
Correct |
2 ms |
7004 KB |
Output is correct |
38 |
Correct |
2 ms |
7004 KB |
Output is correct |
39 |
Correct |
2 ms |
7004 KB |
Output is correct |
40 |
Correct |
2 ms |
7004 KB |
Output is correct |
41 |
Correct |
3 ms |
7004 KB |
Output is correct |
42 |
Correct |
2 ms |
7000 KB |
Output is correct |
43 |
Correct |
2 ms |
7076 KB |
Output is correct |
44 |
Correct |
2 ms |
7004 KB |
Output is correct |
45 |
Correct |
2 ms |
7004 KB |
Output is correct |
46 |
Correct |
4 ms |
7004 KB |
Output is correct |
47 |
Correct |
2 ms |
7000 KB |
Output is correct |
48 |
Correct |
2 ms |
7256 KB |
Output is correct |
49 |
Correct |
2 ms |
7256 KB |
Output is correct |
50 |
Correct |
2 ms |
7004 KB |
Output is correct |
51 |
Correct |
2 ms |
7004 KB |
Output is correct |
52 |
Correct |
2 ms |
7044 KB |
Output is correct |
53 |
Correct |
5 ms |
7004 KB |
Output is correct |
54 |
Correct |
2 ms |
4956 KB |
Output is correct |
55 |
Correct |
31 ms |
73132 KB |
Output is correct |
56 |
Correct |
3 ms |
7260 KB |
Output is correct |
57 |
Correct |
11 ms |
74844 KB |
Output is correct |
58 |
Correct |
40 ms |
50292 KB |
Output is correct |
59 |
Correct |
360 ms |
199396 KB |
Output is correct |
60 |
Correct |
350 ms |
199500 KB |
Output is correct |
61 |
Correct |
333 ms |
199492 KB |
Output is correct |
62 |
Correct |
2 ms |
4956 KB |
Output is correct |
63 |
Correct |
329 ms |
196212 KB |
Output is correct |
64 |
Correct |
267 ms |
199288 KB |
Output is correct |
65 |
Correct |
260 ms |
199312 KB |
Output is correct |
66 |
Correct |
270 ms |
199492 KB |
Output is correct |
67 |
Correct |
251 ms |
166716 KB |
Output is correct |
68 |
Correct |
261 ms |
193452 KB |
Output is correct |
69 |
Correct |
259 ms |
199292 KB |
Output is correct |
70 |
Correct |
30 ms |
50312 KB |
Output is correct |
71 |
Correct |
27 ms |
50444 KB |
Output is correct |
72 |
Correct |
28 ms |
50264 KB |
Output is correct |
73 |
Correct |
29 ms |
50288 KB |
Output is correct |
74 |
Correct |
27 ms |
50268 KB |
Output is correct |
75 |
Correct |
31 ms |
50264 KB |
Output is correct |
76 |
Correct |
31 ms |
50268 KB |
Output is correct |
77 |
Correct |
31 ms |
50252 KB |
Output is correct |
78 |
Correct |
27 ms |
50268 KB |
Output is correct |
79 |
Correct |
31 ms |
50260 KB |
Output is correct |
80 |
Correct |
28 ms |
50516 KB |
Output is correct |
81 |
Correct |
32 ms |
50260 KB |
Output is correct |
82 |
Correct |
38 ms |
50268 KB |
Output is correct |
83 |
Correct |
29 ms |
50380 KB |
Output is correct |
84 |
Correct |
31 ms |
50488 KB |
Output is correct |
85 |
Correct |
28 ms |
50308 KB |
Output is correct |
86 |
Correct |
32 ms |
50556 KB |
Output is correct |
87 |
Correct |
28 ms |
50304 KB |
Output is correct |
88 |
Correct |
40 ms |
50296 KB |
Output is correct |
89 |
Correct |
30 ms |
50220 KB |
Output is correct |
90 |
Correct |
27 ms |
50256 KB |
Output is correct |