Submission #339039

# Submission time Handle Problem Language Result Execution time Memory
339039 2020-12-24T13:01:43 Z sinamhdv Dango Maker (JOI18_dango_maker) C++11
100 / 100
648 ms 161516 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1000 * 1000 * 1000;
const ll LINF = (ll)INF * INF;

#ifdef DEBUG
#define dbg(x) cout << #x << " = " << (x) << endl << flush;
#define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; }
#else
#define dbg(x) ;
#define dbgr(s, f) ;
#endif
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define msub(a, b) ((mod + ((ll)(a) - (b)) % mod) % mod)
#define mdiv(a, b) ((ll)(a) * poww((b), mod - 2) % mod)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define endl '\n'

#define MAXN 3050

int n, m;
char grid[MAXN][MAXN];
int dirs[MAXN][MAXN];
int dp[3][MAXN][MAXN];

inline void filldp(int x, int y)
{
	dp[0][x][y] = max(dp[0][x - 1][y + 1], max(dp[1][x - 1][y + 1], dp[2][x - 1][y + 1]));
	if (dirs[x][y] & 2)
		dp[2][x][y] = dp[0][x][y] + 1;
	if (dirs[x][y] & 1)
		dp[1][x][y] = max(dp[1][x - 1][y + 1], max(dp[0][x - 2][y + 2], dp[1][x - 2][y + 2])) + 1;
}

int32_t main(void)
{
	fast_io;
	cin >> n >> m;
	FOR(i, 0, n)
	{
		FOR(j, 0, m)
		{
			cin >> grid[i][j];
		}
	}
	FOR(i, 0, n)
	{
		FOR(j, 0, m)
		{
			if (grid[i][j] == 'R' && grid[i][j + 1] == 'G' && grid[i][j + 2] == 'W')
				dirs[i + 1][j + 1] |= 1;
			if (grid[i][j] == 'R' && grid[i + 1][j] == 'G' && grid[i + 2][j] == 'W')
				dirs[i + 1][j + 1] |= 2;
		}
	}

	FOR(i, 1, m + 1)
	{
		dp[1][1][i] = dirs[1][i] & 1;
		dp[2][1][i] = ((dirs[1][i] & 2) > 0);
	}
	FOR(i, 2, n + 1)
	{
		dp[2][i][m] = ((dirs[i][m] & 2) > 0);
	}

	FOR(i, 2, m + 1)
	{
		for (int x = 2, y = i - 1; x <= n && y > 0; x++, y--)
		{
			filldp(x, y);
		}
	}

	FOR(i, 2, n + 1)
	{
		for (int x = i + 1, y = m - 1; x <= n && y > 0; x++, y--)
		{
			filldp(x, y);
		}
	}

	int ans = 0;
	FOR(i, 1, n + 1)
	{
		ans += max(dp[0][i][1], max(dp[1][i][1], dp[2][i][1]));
	}
	FOR(i, 2, m + 1)
	{
		ans += max(dp[0][n][i], max(dp[1][n][i], dp[2][n][i]));
	}

	cout << ans << endl;
	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 512 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 1 ms 492 KB Output is correct
35 Correct 1 ms 492 KB Output is correct
36 Correct 1 ms 492 KB Output is correct
37 Correct 1 ms 492 KB Output is correct
38 Correct 1 ms 492 KB Output is correct
39 Correct 1 ms 504 KB Output is correct
40 Correct 1 ms 492 KB Output is correct
41 Correct 1 ms 492 KB Output is correct
42 Correct 1 ms 492 KB Output is correct
43 Correct 1 ms 492 KB Output is correct
44 Correct 1 ms 492 KB Output is correct
45 Correct 1 ms 492 KB Output is correct
46 Correct 1 ms 492 KB Output is correct
47 Correct 1 ms 512 KB Output is correct
48 Correct 1 ms 492 KB Output is correct
49 Correct 1 ms 492 KB Output is correct
50 Correct 1 ms 492 KB Output is correct
51 Correct 1 ms 492 KB Output is correct
52 Correct 1 ms 620 KB Output is correct
53 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 512 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 1 ms 492 KB Output is correct
35 Correct 1 ms 492 KB Output is correct
36 Correct 1 ms 492 KB Output is correct
37 Correct 1 ms 492 KB Output is correct
38 Correct 1 ms 492 KB Output is correct
39 Correct 1 ms 504 KB Output is correct
40 Correct 1 ms 492 KB Output is correct
41 Correct 1 ms 492 KB Output is correct
42 Correct 1 ms 492 KB Output is correct
43 Correct 1 ms 492 KB Output is correct
44 Correct 1 ms 492 KB Output is correct
45 Correct 1 ms 492 KB Output is correct
46 Correct 1 ms 492 KB Output is correct
47 Correct 1 ms 512 KB Output is correct
48 Correct 1 ms 492 KB Output is correct
49 Correct 1 ms 492 KB Output is correct
50 Correct 1 ms 492 KB Output is correct
51 Correct 1 ms 492 KB Output is correct
52 Correct 1 ms 620 KB Output is correct
53 Correct 1 ms 492 KB Output is correct
54 Correct 1 ms 364 KB Output is correct
55 Correct 17 ms 21996 KB Output is correct
56 Correct 1 ms 620 KB Output is correct
57 Correct 20 ms 34668 KB Output is correct
58 Correct 79 ms 35692 KB Output is correct
59 Correct 646 ms 161388 KB Output is correct
60 Correct 648 ms 161316 KB Output is correct
61 Correct 626 ms 161388 KB Output is correct
62 Correct 1 ms 492 KB Output is correct
63 Correct 637 ms 161132 KB Output is correct
64 Correct 556 ms 161388 KB Output is correct
65 Correct 565 ms 161388 KB Output is correct
66 Correct 560 ms 161516 KB Output is correct
67 Correct 490 ms 89884 KB Output is correct
68 Correct 494 ms 90288 KB Output is correct
69 Correct 495 ms 105452 KB Output is correct
70 Correct 64 ms 36096 KB Output is correct
71 Correct 64 ms 35948 KB Output is correct
72 Correct 65 ms 35948 KB Output is correct
73 Correct 63 ms 35948 KB Output is correct
74 Correct 64 ms 36076 KB Output is correct
75 Correct 71 ms 35948 KB Output is correct
76 Correct 63 ms 35948 KB Output is correct
77 Correct 63 ms 35948 KB Output is correct
78 Correct 65 ms 35948 KB Output is correct
79 Correct 69 ms 36076 KB Output is correct
80 Correct 65 ms 35948 KB Output is correct
81 Correct 64 ms 35948 KB Output is correct
82 Correct 63 ms 35948 KB Output is correct
83 Correct 63 ms 35948 KB Output is correct
84 Correct 64 ms 36160 KB Output is correct
85 Correct 65 ms 35948 KB Output is correct
86 Correct 63 ms 35948 KB Output is correct
87 Correct 64 ms 35948 KB Output is correct
88 Correct 63 ms 35948 KB Output is correct
89 Correct 64 ms 35948 KB Output is correct
90 Correct 65 ms 35948 KB Output is correct