Submission #951389

# Submission time Handle Problem Language Result Execution time Memory
951389 2024-03-21T22:06:27 Z starchan Dango Maker (JOI18_dango_maker) C++17
100 / 100
249 ms 159804 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define in pair<int, int>
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define INF (int)1e17
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
const int SMX = 3e3+5;
char grid[SMX][SMX];
int gud[SMX][SMX][2];//automatically set to zero anyway
int solve(int DIAG, int l, int r)
{
	int n = r-l+1;
	int dp[n+1][2];
	dp[0][0] = dp[0][1] = 0;
	dp[1][0] = gud[l][DIAG-l][0]; dp[1][1] = gud[l][DIAG-l][1];
	for(int i = 2; i <= n; i++)
	{
		dp[i][0] = gud[l-1+i][DIAG-l+1-i][0]+max(dp[i-1][0], max(dp[i-2][0], dp[i-2][1]));
		dp[i][1] = gud[l-1+i][DIAG-l+1-i][1]+max(dp[i-1][1], max(dp[i-2][0], dp[i-2][1]));
	}
	int ans = 0;
	for(int i = 0; i <= n; i++)
		ans = max(ans, max(dp[i][0], dp[i][1]));
	return ans;
}
signed main()
{
	fast();
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
			cin >> grid[i][j];
	}
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
		{
			if(grid[i][j] != 'G')
				continue;
			if((i > 0) && (i < (n-1)) && (grid[i-1][j] == 'R') && (grid[i+1][j] == 'W'))
				gud[i][j][0] = 1;
			if((j > 0) && (j < (m-1)) && (grid[i][j-1] == 'R') && (grid[i][j+1] == 'W'))
				gud[i][j][1] = 1;
		}
	}
	int ans = 0;
	int l[n+m-1], r[n+m-1];
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
			r[i+j] = i;
	}
	for(int i = n-1; i >= 0; i--)
	{
		for(int j = 0; j < m; j++)
			l[i+j] = i;
	}
	for(int DIAG = 0; DIAG <= n+m-2; DIAG++)
		ans+=solve(DIAG, l[DIAG], r[DIAG]);
	cout << ans << "\n";
	return 0;
}	
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4556 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 2 ms 4444 KB Output is correct
29 Correct 4 ms 4440 KB Output is correct
30 Correct 1 ms 4440 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 2 ms 4856 KB Output is correct
36 Correct 1 ms 4440 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4440 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 4560 KB Output is correct
42 Correct 1 ms 4696 KB Output is correct
43 Correct 1 ms 4440 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4444 KB Output is correct
50 Correct 1 ms 4440 KB Output is correct
51 Correct 1 ms 4444 KB Output is correct
52 Correct 1 ms 4444 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4556 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 2 ms 4444 KB Output is correct
29 Correct 4 ms 4440 KB Output is correct
30 Correct 1 ms 4440 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 2 ms 4856 KB Output is correct
36 Correct 1 ms 4440 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4440 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 4560 KB Output is correct
42 Correct 1 ms 4696 KB Output is correct
43 Correct 1 ms 4440 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4444 KB Output is correct
50 Correct 1 ms 4440 KB Output is correct
51 Correct 1 ms 4444 KB Output is correct
52 Correct 1 ms 4444 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 58 ms 119760 KB Output is correct
56 Correct 1 ms 4700 KB Output is correct
57 Correct 13 ms 103192 KB Output is correct
58 Correct 29 ms 54876 KB Output is correct
59 Correct 249 ms 159544 KB Output is correct
60 Correct 244 ms 159316 KB Output is correct
61 Correct 242 ms 159572 KB Output is correct
62 Correct 1 ms 2396 KB Output is correct
63 Correct 233 ms 159028 KB Output is correct
64 Correct 189 ms 159556 KB Output is correct
65 Correct 194 ms 159804 KB Output is correct
66 Correct 193 ms 159568 KB Output is correct
67 Correct 185 ms 159312 KB Output is correct
68 Correct 193 ms 159584 KB Output is correct
69 Correct 193 ms 159316 KB Output is correct
70 Correct 23 ms 54904 KB Output is correct
71 Correct 23 ms 54696 KB Output is correct
72 Correct 23 ms 54996 KB Output is correct
73 Correct 23 ms 54872 KB Output is correct
74 Correct 23 ms 54876 KB Output is correct
75 Correct 26 ms 54868 KB Output is correct
76 Correct 24 ms 54876 KB Output is correct
77 Correct 24 ms 54848 KB Output is correct
78 Correct 24 ms 54876 KB Output is correct
79 Correct 23 ms 54872 KB Output is correct
80 Correct 24 ms 54916 KB Output is correct
81 Correct 23 ms 54848 KB Output is correct
82 Correct 22 ms 54876 KB Output is correct
83 Correct 24 ms 54868 KB Output is correct
84 Correct 25 ms 54872 KB Output is correct
85 Correct 24 ms 54876 KB Output is correct
86 Correct 24 ms 54876 KB Output is correct
87 Correct 24 ms 54872 KB Output is correct
88 Correct 23 ms 54876 KB Output is correct
89 Correct 23 ms 54876 KB Output is correct
90 Correct 24 ms 54888 KB Output is correct