/*
IN THE NAME OF GOD
*/
#include <bits/stdc++.h>
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;
#define F first
#define S second
#define Mp make_pair
#define pb push_back
#define pf push_front
#define size(x) ((ll)x.size())
#define all(x) (x).begin(),(x).end()
#define kill(x) cout << x << '\n', exit(0);
#define fuck(x) cout << "(" << #x << " , " << x << ")" << endl
#define endl '\n'
const int N = 3e3+23, lg = 20;
ll Mod = 1e9+7; //998244353;
inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
ll ans = 1;
a=MOD(a, mod);
while (b) {
if (b & 1) ans = MOD(ans*a, mod);
b >>= 1;
a = MOD(a*a, mod);
}
return ans;
}
int n, m, ans, dp[2*N][3][3], ok[N][N][2], a[N][N];
bool inGrid(int x, int y) {
if(x>0&&x<=n&&y>0&&y<=m) return 1;
return 0;
}
int main () {
ios_base::sync_with_stdio(false), cin.tie(0);
cin>>n>>m;
for(int i=1; i<=n; i++) {
for(int j=1; j<=m; j++) {
char ch; cin>>ch;
if(ch=='G') a[i][j]=1;
if(ch=='W') a[i][j]=2;
}
}
for(int i=1; i<=n; i++) {
for(int j=1; j<=m; j++) {
if(a[i][j]==0 && a[i+1][j]==1 && a[i+2][j]==2) ok[i][j][0] = 1;
if(a[i][j]==0 && a[i][j+1]==1 && a[i][j+2]==2) ok[i][j][1] = 1;
}
}
for(int ij=1; ij<=n+m; ij++) {
int cnt = 1;
for(int j,i=1; i<=n&&i<ij; i++) {
j = ij-i;
if(inGrid(i,j)==0) continue;
dp[cnt][2][0] = max({dp[cnt-1][0][0], dp[cnt-1][0][1], dp[cnt-1][0][2]});
dp[cnt][2][1] = max({dp[cnt-1][1][0], dp[cnt-1][1][1], dp[cnt-1][1][2]});
dp[cnt][2][2] = max({dp[cnt-1][2][0], dp[cnt-1][2][1], dp[cnt-1][2][2]});
if(ok[i][j][0] == 1) {
dp[cnt][0][0] = 1+dp[cnt][2][0];
dp[cnt][0][1] = 1+dp[cnt][2][1];
dp[cnt][0][2] = 1+dp[cnt][2][2];
}
if(ok[i][j][1] == 1) {
dp[cnt][1][2] = 1+max(dp[cnt-1][2][1], dp[cnt-1][2][2]);
dp[cnt][1][1] = 1+max(dp[cnt-1][1][1], dp[cnt-1][1][2]);
}
cnt++;
}
int mx = 0;
for(int i=0; i<3; i++) for(int j=0; j<3; j++) mx = max(mx, dp[cnt-1][i][j]);
ans += mx;
for(int l=1; l<cnt; l++) {
for(int i=0; i<3; i++) for(int j=0; j<3; j++) dp[l][i][j] = 0;
}
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
548 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
548 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2392 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2392 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
2392 KB |
Output is correct |
28 |
Correct |
1 ms |
2392 KB |
Output is correct |
29 |
Correct |
1 ms |
2392 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
1 ms |
2392 KB |
Output is correct |
33 |
Correct |
1 ms |
2392 KB |
Output is correct |
34 |
Correct |
1 ms |
2392 KB |
Output is correct |
35 |
Correct |
1 ms |
2648 KB |
Output is correct |
36 |
Correct |
1 ms |
2392 KB |
Output is correct |
37 |
Correct |
1 ms |
2392 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2392 KB |
Output is correct |
40 |
Correct |
1 ms |
2392 KB |
Output is correct |
41 |
Correct |
1 ms |
2392 KB |
Output is correct |
42 |
Correct |
1 ms |
2392 KB |
Output is correct |
43 |
Correct |
1 ms |
2392 KB |
Output is correct |
44 |
Correct |
1 ms |
2392 KB |
Output is correct |
45 |
Correct |
1 ms |
2392 KB |
Output is correct |
46 |
Correct |
1 ms |
2392 KB |
Output is correct |
47 |
Correct |
1 ms |
2392 KB |
Output is correct |
48 |
Correct |
1 ms |
2396 KB |
Output is correct |
49 |
Correct |
1 ms |
2392 KB |
Output is correct |
50 |
Correct |
1 ms |
2392 KB |
Output is correct |
51 |
Correct |
1 ms |
2392 KB |
Output is correct |
52 |
Correct |
2 ms |
2396 KB |
Output is correct |
53 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
548 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2392 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2392 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
2392 KB |
Output is correct |
28 |
Correct |
1 ms |
2392 KB |
Output is correct |
29 |
Correct |
1 ms |
2392 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
1 ms |
2392 KB |
Output is correct |
33 |
Correct |
1 ms |
2392 KB |
Output is correct |
34 |
Correct |
1 ms |
2392 KB |
Output is correct |
35 |
Correct |
1 ms |
2648 KB |
Output is correct |
36 |
Correct |
1 ms |
2392 KB |
Output is correct |
37 |
Correct |
1 ms |
2392 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2392 KB |
Output is correct |
40 |
Correct |
1 ms |
2392 KB |
Output is correct |
41 |
Correct |
1 ms |
2392 KB |
Output is correct |
42 |
Correct |
1 ms |
2392 KB |
Output is correct |
43 |
Correct |
1 ms |
2392 KB |
Output is correct |
44 |
Correct |
1 ms |
2392 KB |
Output is correct |
45 |
Correct |
1 ms |
2392 KB |
Output is correct |
46 |
Correct |
1 ms |
2392 KB |
Output is correct |
47 |
Correct |
1 ms |
2392 KB |
Output is correct |
48 |
Correct |
1 ms |
2396 KB |
Output is correct |
49 |
Correct |
1 ms |
2392 KB |
Output is correct |
50 |
Correct |
1 ms |
2392 KB |
Output is correct |
51 |
Correct |
1 ms |
2392 KB |
Output is correct |
52 |
Correct |
2 ms |
2396 KB |
Output is correct |
53 |
Correct |
1 ms |
2392 KB |
Output is correct |
54 |
Correct |
1 ms |
2392 KB |
Output is correct |
55 |
Correct |
25 ms |
102992 KB |
Output is correct |
56 |
Correct |
2 ms |
2392 KB |
Output is correct |
57 |
Correct |
13 ms |
74328 KB |
Output is correct |
58 |
Correct |
40 ms |
38472 KB |
Output is correct |
59 |
Correct |
368 ms |
116304 KB |
Output is correct |
60 |
Correct |
367 ms |
116048 KB |
Output is correct |
61 |
Correct |
366 ms |
116048 KB |
Output is correct |
62 |
Correct |
1 ms |
2392 KB |
Output is correct |
63 |
Correct |
367 ms |
116216 KB |
Output is correct |
64 |
Correct |
236 ms |
116208 KB |
Output is correct |
65 |
Correct |
238 ms |
116232 KB |
Output is correct |
66 |
Correct |
232 ms |
115992 KB |
Output is correct |
67 |
Correct |
238 ms |
116160 KB |
Output is correct |
68 |
Correct |
229 ms |
116048 KB |
Output is correct |
69 |
Correct |
253 ms |
116480 KB |
Output is correct |
70 |
Correct |
25 ms |
38488 KB |
Output is correct |
71 |
Correct |
26 ms |
38488 KB |
Output is correct |
72 |
Correct |
26 ms |
38492 KB |
Output is correct |
73 |
Correct |
27 ms |
38488 KB |
Output is correct |
74 |
Correct |
25 ms |
38488 KB |
Output is correct |
75 |
Correct |
27 ms |
38488 KB |
Output is correct |
76 |
Correct |
24 ms |
38444 KB |
Output is correct |
77 |
Correct |
25 ms |
38484 KB |
Output is correct |
78 |
Correct |
24 ms |
38488 KB |
Output is correct |
79 |
Correct |
27 ms |
38456 KB |
Output is correct |
80 |
Correct |
24 ms |
38488 KB |
Output is correct |
81 |
Correct |
25 ms |
38476 KB |
Output is correct |
82 |
Correct |
24 ms |
38488 KB |
Output is correct |
83 |
Correct |
29 ms |
38492 KB |
Output is correct |
84 |
Correct |
24 ms |
38488 KB |
Output is correct |
85 |
Correct |
25 ms |
38476 KB |
Output is correct |
86 |
Correct |
25 ms |
38488 KB |
Output is correct |
87 |
Correct |
26 ms |
38488 KB |
Output is correct |
88 |
Correct |
27 ms |
38680 KB |
Output is correct |
89 |
Correct |
26 ms |
38480 KB |
Output is correct |
90 |
Correct |
25 ms |
38480 KB |
Output is correct |