#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define russian setlocale(LC_ALL,"Russian_Russia.20866");
#define file freopen("onlyone.in", "r", stdin), freopen("onlyone.out", "w", stdout);
#define ll long long
//#define int long long
#define ull unsigned long long
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define all(s) s.begin(), s.end()
#define pb push_back
#define ins insert
#define mp make_pair
#define sz(x) x.size()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define mem(x) memset(x, 0, sizeof(x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll N = 3010;
const ll M = 600000;
const ll block = 316;
const ll mod = 1e9 + 7;
const ll P = 263;
const ld pi = acos(-1);
const ll inf = 1e9;
ll add(ll a, ll b) {
if(a + b < 0) return a + b + mod;
if(a + b >= mod) return a + b - mod;
return a + b;
}
ll sub(ll a, ll b) {
return (a - b + mod) % mod;
}
ll mul(ll a, ll b) {
return a * 1LL * b % mod;
}
ll binpow(ll a, ll n) {
ll res = 1;
while(n) {
if (n & 1) res = mul(res, a);
a = mul(a, a);
n >>= 1;
}
return res;
}
ll inv(ll x) {
return binpow(x, mod - 2);
}
int n, m;
char a[N][N];
string order = "RGW";
int dp[3][N][N];//0 - max both, 1 - horizontal, 2 - vetical
bool check(int x, int y) {
return (1 <= x && x <= n && 1 <= y && y <= m);
}
int horizontal(int i, int j) {
int ok = 1;
for(int k = 0; k < 3; k++) {
ok &= (check(i, j + k - 1) && a[i][j + k - 1] == order[k]);
}
return ok;
}
int vertical(int i, int j) {
int ok = 1;
for(int k = 0; k < 3; k++) {
ok &= (check(i + k - 1, j) && a[i + k - 1][j] == order[k]);
}
return ok;
}
void solve() {
cin >> n >> m;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
dp[0][0][0] = dp[1][0][0] = dp[2][0][0] = 0;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
dp[0][i][j] = max({dp[0][i][j], dp[1][i - 1][j + 1], dp[2][i - 1][j + 1]});
dp[1][i][j] = max(dp[0][i][j], dp[1][i - 1][j + 1] + horizontal(i, j));
dp[2][i][j] = max(dp[0][i][j], dp[2][i - 1][j + 1] + vertical(i, j));
}
}
int ans = 0;
for(int i = 1; i <= n; i++) ans += max(dp[1][i][1], dp[2][i][1]);
for(int j = 2; j <= m; j++) ans += max(dp[1][n][j], dp[2][n][j]);
cout << ans << '\n';
}
signed main() {
speed;
//file
int test = 1;
//cin >> test;
while(test--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6648 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 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 |
6744 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6648 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 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 |
6744 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 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 |
6492 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 |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6624 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
6488 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
1 ms |
6492 KB |
Output is correct |
32 |
Correct |
1 ms |
6492 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 |
0 ms |
6492 KB |
Output is correct |
38 |
Correct |
1 ms |
6492 KB |
Output is correct |
39 |
Correct |
1 ms |
6492 KB |
Output is correct |
40 |
Correct |
1 ms |
6492 KB |
Output is correct |
41 |
Correct |
1 ms |
6492 KB |
Output is correct |
42 |
Correct |
0 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 |
6492 KB |
Output is correct |
51 |
Correct |
1 ms |
6492 KB |
Output is correct |
52 |
Correct |
1 ms |
6492 KB |
Output is correct |
53 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6648 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 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 |
6744 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 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 |
6492 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 |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6624 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
6488 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
1 ms |
6492 KB |
Output is correct |
32 |
Correct |
1 ms |
6492 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 |
0 ms |
6492 KB |
Output is correct |
38 |
Correct |
1 ms |
6492 KB |
Output is correct |
39 |
Correct |
1 ms |
6492 KB |
Output is correct |
40 |
Correct |
1 ms |
6492 KB |
Output is correct |
41 |
Correct |
1 ms |
6492 KB |
Output is correct |
42 |
Correct |
0 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 |
6492 KB |
Output is correct |
51 |
Correct |
1 ms |
6492 KB |
Output is correct |
52 |
Correct |
1 ms |
6492 KB |
Output is correct |
53 |
Correct |
1 ms |
6492 KB |
Output is correct |
54 |
Correct |
1 ms |
6492 KB |
Output is correct |
55 |
Correct |
13 ms |
92544 KB |
Output is correct |
56 |
Correct |
1 ms |
6492 KB |
Output is correct |
57 |
Correct |
7 ms |
65880 KB |
Output is correct |
58 |
Correct |
22 ms |
41176 KB |
Output is correct |
59 |
Correct |
249 ms |
115404 KB |
Output is correct |
60 |
Correct |
168 ms |
115536 KB |
Output is correct |
61 |
Correct |
171 ms |
115404 KB |
Output is correct |
62 |
Correct |
1 ms |
6492 KB |
Output is correct |
63 |
Correct |
191 ms |
115408 KB |
Output is correct |
64 |
Correct |
165 ms |
115660 KB |
Output is correct |
65 |
Correct |
230 ms |
115544 KB |
Output is correct |
66 |
Correct |
177 ms |
115420 KB |
Output is correct |
67 |
Correct |
176 ms |
115536 KB |
Output is correct |
68 |
Correct |
193 ms |
115504 KB |
Output is correct |
69 |
Correct |
174 ms |
115540 KB |
Output is correct |
70 |
Correct |
23 ms |
41036 KB |
Output is correct |
71 |
Correct |
22 ms |
41040 KB |
Output is correct |
72 |
Correct |
29 ms |
41052 KB |
Output is correct |
73 |
Correct |
44 ms |
41296 KB |
Output is correct |
74 |
Correct |
22 ms |
41048 KB |
Output is correct |
75 |
Correct |
29 ms |
41112 KB |
Output is correct |
76 |
Correct |
27 ms |
41052 KB |
Output is correct |
77 |
Correct |
29 ms |
40964 KB |
Output is correct |
78 |
Correct |
42 ms |
41044 KB |
Output is correct |
79 |
Correct |
25 ms |
41048 KB |
Output is correct |
80 |
Correct |
22 ms |
41160 KB |
Output is correct |
81 |
Correct |
42 ms |
41044 KB |
Output is correct |
82 |
Correct |
22 ms |
41180 KB |
Output is correct |
83 |
Correct |
42 ms |
41040 KB |
Output is correct |
84 |
Correct |
22 ms |
41180 KB |
Output is correct |
85 |
Correct |
22 ms |
41108 KB |
Output is correct |
86 |
Correct |
42 ms |
41040 KB |
Output is correct |
87 |
Correct |
22 ms |
41052 KB |
Output is correct |
88 |
Correct |
22 ms |
41044 KB |
Output is correct |
89 |
Correct |
23 ms |
41052 KB |
Output is correct |
90 |
Correct |
36 ms |
41044 KB |
Output is correct |