#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#ifdef lisie_bimbi
#else
#define endl '\n'
#endif
typedef long long ll;
const ll inf = 1'000'000'000'000'000'000;
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,bmi2,fma,popcnt")
//#define int long long
int n, m;
vector<vector<int>> z;
bool get(int x, int y, bool f){
if((x >= 0) && (x < n) && (y >= 0) && (y < m)){
}else{
return 0;
}
if(f){
if(x + 2 < n){
return ((z[x][y] == 0) && (z[x + 1][y] == 1) && (z[x + 2][y] == 2));
}else{
return 0;
}
}else{
if(y + 2 < m){
return ((z[x][y] == 0) && (z[x][y + 1] == 1) && (z[x][y + 2] == 2));
}else{
return 0;
}
}
}
int solve1(vector<int> a, vector<int> b){
/*
for(auto i : a){
cout << i << " ";
}
cout << endl;
for(auto i : b){
cout << i << " ";
}
cout << endl;
cout << endl;
*/
int n = a.size();
vector<vector<int>> dp(n + 1, vector<int>(3));
dp[0] = {0, 0, 0};
for(int i = 0; i < n; i++){
dp[i + 1][0] = dp[i][0];
dp[i + 1][1] = dp[i][0];
dp[i + 1][2] = dp[i][1];
if(b[i]){
dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + 1);
}
if(a[i]){
dp[i + 1][0] = max(dp[i + 1][0], dp[i][2] + 1);
dp[i + 1][1] = max(dp[i + 1][1], dp[i][2] + 1);
dp[i + 1][2] = max(dp[i + 1][2], dp[i][2] + 1);
}
}
return dp.back()[0];
}
void solve(){
cin >> n >> m;
z.resize(n, vector<int>(m));
for(int i = 0; i < n; i++){
string s;
cin >> s;
for(int j = 0; j < m; j++){
if(s[j] == 'R'){
z[i][j] = 0;
}else if(s[j] == 'G'){
z[i][j] = 1;
}else{
z[i][j] = 2;
}
}
}
int ans = 0;
for(int sum = 0; sum < n + m - 1; sum++){
vector<int> a, b;
for(int j = 0; j < m; j++){
int i = sum - j;
if((i >= 0) && (i < n)){
a.push_back(get(i, j, 1));
b.push_back(get(i, j, 0));
}
}
ans += solve1(a, b);
}
cout << ans << endl;
}
signed main(){
#ifdef lisie_bimbi
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
cin.tie(nullptr)->sync_with_stdio(false);
#endif
cout << setprecision(5) << fixed;
int _ = 1;
//cin >> t;
while(_--){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
352 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
352 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
608 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
460 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
352 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
352 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
352 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
352 KB |
Output is correct |
34 |
Correct |
0 ms |
356 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
352 KB |
Output is correct |
37 |
Correct |
1 ms |
352 KB |
Output is correct |
38 |
Correct |
1 ms |
352 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
352 KB |
Output is correct |
43 |
Correct |
0 ms |
352 KB |
Output is correct |
44 |
Correct |
0 ms |
352 KB |
Output is correct |
45 |
Correct |
0 ms |
356 KB |
Output is correct |
46 |
Correct |
0 ms |
360 KB |
Output is correct |
47 |
Correct |
1 ms |
352 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
352 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
608 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
460 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
352 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
352 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
352 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
352 KB |
Output is correct |
34 |
Correct |
0 ms |
356 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
352 KB |
Output is correct |
37 |
Correct |
1 ms |
352 KB |
Output is correct |
38 |
Correct |
1 ms |
352 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
352 KB |
Output is correct |
43 |
Correct |
0 ms |
352 KB |
Output is correct |
44 |
Correct |
0 ms |
352 KB |
Output is correct |
45 |
Correct |
0 ms |
356 KB |
Output is correct |
46 |
Correct |
0 ms |
360 KB |
Output is correct |
47 |
Correct |
1 ms |
352 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
9 ms |
348 KB |
Output is correct |
55 |
Correct |
2 ms |
604 KB |
Output is correct |
56 |
Correct |
6 ms |
540 KB |
Output is correct |
57 |
Correct |
2 ms |
604 KB |
Output is correct |
58 |
Correct |
55 ms |
5500 KB |
Output is correct |
59 |
Correct |
539 ms |
44980 KB |
Output is correct |
60 |
Correct |
549 ms |
44880 KB |
Output is correct |
61 |
Correct |
575 ms |
44876 KB |
Output is correct |
62 |
Correct |
7 ms |
344 KB |
Output is correct |
63 |
Correct |
506 ms |
43408 KB |
Output is correct |
64 |
Correct |
448 ms |
45120 KB |
Output is correct |
65 |
Correct |
481 ms |
44872 KB |
Output is correct |
66 |
Correct |
489 ms |
45080 KB |
Output is correct |
67 |
Correct |
458 ms |
44876 KB |
Output is correct |
68 |
Correct |
458 ms |
44872 KB |
Output is correct |
69 |
Correct |
472 ms |
44880 KB |
Output is correct |
70 |
Correct |
45 ms |
5424 KB |
Output is correct |
71 |
Correct |
47 ms |
5464 KB |
Output is correct |
72 |
Correct |
45 ms |
5516 KB |
Output is correct |
73 |
Correct |
55 ms |
5468 KB |
Output is correct |
74 |
Correct |
47 ms |
5508 KB |
Output is correct |
75 |
Correct |
48 ms |
5468 KB |
Output is correct |
76 |
Correct |
44 ms |
5464 KB |
Output is correct |
77 |
Correct |
60 ms |
5468 KB |
Output is correct |
78 |
Correct |
51 ms |
5468 KB |
Output is correct |
79 |
Correct |
45 ms |
5468 KB |
Output is correct |
80 |
Correct |
56 ms |
5512 KB |
Output is correct |
81 |
Correct |
45 ms |
5468 KB |
Output is correct |
82 |
Correct |
45 ms |
5508 KB |
Output is correct |
83 |
Correct |
49 ms |
5304 KB |
Output is correct |
84 |
Correct |
50 ms |
5464 KB |
Output is correct |
85 |
Correct |
62 ms |
5468 KB |
Output is correct |
86 |
Correct |
48 ms |
5508 KB |
Output is correct |
87 |
Correct |
46 ms |
5468 KB |
Output is correct |
88 |
Correct |
45 ms |
5468 KB |
Output is correct |
89 |
Correct |
51 ms |
5464 KB |
Output is correct |
90 |
Correct |
50 ms |
5504 KB |
Output is correct |