Submission #390308

# Submission time Handle Problem Language Result Execution time Memory
390308 2021-04-15T19:56:21 Z idontreallyknow Dango Maker (JOI18_dango_maker) C++17
100 / 100
912 ms 112076 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class A> ostream& operator<<(ostream &cout, vector<A> const &v) {cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";};
template<class A, class B> ostream& operator<<(ostream &cout, const pair<A,B> &x) {return cout << "(" <<x.first << ", " << x.second << ")";};
template<class T> void pv(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) cerr << *i << " "; cerr << "]\n";}
void _print() {cerr << "]\n";}
template<class T, class... V> void _print(T t, V... v) {cerr << t; if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "[" << #x << "] = [", _print(x)
#define fi first
#define se second
#define SZ(x) (int)((x).size())
#define pii pair<int,int>
int n,m;
string grid[3000];
bool exist(int a, int b, int c) {
	if (a < 0 || a >= n || b < 0 || b >= m) return false;
	if (c == 0) {
		if (a-1 >= 0 && a+1 < n && grid[a-1][b] == 'R' && grid[a][b] == 'G' && grid[a+1][b] == 'W') return true;
	} else {
		if (b-1 >= 0 && b+1 < m && grid[a][b-1] == 'R' && grid[a][b] == 'G' && grid[a][b+1] == 'W') return true;
	}
	return false;
}
vector<pii> diag[6005];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for (int q = 0; q < n; q++) cin >> grid[q];
	for (int q = 0; q < n; q++) {
		for (int w = 0; w < m; w++) {
			diag[q+w].emplace_back(q,w);
		}
	}
	int ans = 0;
	for (int q = 0; q < n+m-1; q++) {
		vector<vector<int>> dp(SZ(diag[q])+3, vector<int>(2));
		for (int w = 2; w <= SZ(diag[q])+1; w++) {
			int x = diag[q][w-2].fi, y = diag[q][w-2].se;
			dp[w][0] = dp[w-1][0];
			dp[w][1] = dp[w-1][1];
			if (exist(x,y,0)) dp[w][0] = max(dp[w][0], max(dp[w-1][0], dp[w-2][1])+1);
			if (exist(x,y,1)) dp[w][1] = max(dp[w][1], max(dp[w-2][0], dp[w-1][1])+1);
		}
		ans += max(dp[SZ(diag[q])+1][0], dp[SZ(diag[q])+1][1]);
	}
	cout << ans << '\n';
	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 560 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 560 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 556 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 460 KB Output is correct
32 Correct 1 ms 460 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 1 ms 460 KB Output is correct
35 Correct 1 ms 460 KB Output is correct
36 Correct 1 ms 464 KB Output is correct
37 Correct 1 ms 460 KB Output is correct
38 Correct 1 ms 560 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 1 ms 460 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 1 ms 556 KB Output is correct
43 Correct 1 ms 568 KB Output is correct
44 Correct 1 ms 460 KB Output is correct
45 Correct 1 ms 460 KB Output is correct
46 Correct 1 ms 460 KB Output is correct
47 Correct 1 ms 460 KB Output is correct
48 Correct 1 ms 460 KB Output is correct
49 Correct 1 ms 460 KB Output is correct
50 Correct 1 ms 460 KB Output is correct
51 Correct 1 ms 460 KB Output is correct
52 Correct 1 ms 460 KB Output is correct
53 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 560 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 556 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 460 KB Output is correct
32 Correct 1 ms 460 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 1 ms 460 KB Output is correct
35 Correct 1 ms 460 KB Output is correct
36 Correct 1 ms 464 KB Output is correct
37 Correct 1 ms 460 KB Output is correct
38 Correct 1 ms 560 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 1 ms 460 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 1 ms 556 KB Output is correct
43 Correct 1 ms 568 KB Output is correct
44 Correct 1 ms 460 KB Output is correct
45 Correct 1 ms 460 KB Output is correct
46 Correct 1 ms 460 KB Output is correct
47 Correct 1 ms 460 KB Output is correct
48 Correct 1 ms 460 KB Output is correct
49 Correct 1 ms 460 KB Output is correct
50 Correct 1 ms 460 KB Output is correct
51 Correct 1 ms 460 KB Output is correct
52 Correct 1 ms 460 KB Output is correct
53 Correct 1 ms 460 KB Output is correct
54 Correct 1 ms 588 KB Output is correct
55 Correct 1 ms 588 KB Output is correct
56 Correct 2 ms 844 KB Output is correct
57 Correct 2 ms 716 KB Output is correct
58 Correct 86 ms 13228 KB Output is correct
59 Correct 905 ms 111952 KB Output is correct
60 Correct 897 ms 111780 KB Output is correct
61 Correct 912 ms 112076 KB Output is correct
62 Correct 1 ms 588 KB Output is correct
63 Correct 908 ms 108168 KB Output is correct
64 Correct 861 ms 111764 KB Output is correct
65 Correct 826 ms 111848 KB Output is correct
66 Correct 821 ms 111736 KB Output is correct
67 Correct 794 ms 111816 KB Output is correct
68 Correct 789 ms 111884 KB Output is correct
69 Correct 812 ms 111780 KB Output is correct
70 Correct 80 ms 13124 KB Output is correct
71 Correct 78 ms 13240 KB Output is correct
72 Correct 78 ms 13288 KB Output is correct
73 Correct 80 ms 13248 KB Output is correct
74 Correct 85 ms 13132 KB Output is correct
75 Correct 77 ms 13188 KB Output is correct
76 Correct 76 ms 13132 KB Output is correct
77 Correct 78 ms 13236 KB Output is correct
78 Correct 76 ms 13128 KB Output is correct
79 Correct 76 ms 13132 KB Output is correct
80 Correct 77 ms 13144 KB Output is correct
81 Correct 78 ms 13132 KB Output is correct
82 Correct 76 ms 13184 KB Output is correct
83 Correct 79 ms 13252 KB Output is correct
84 Correct 77 ms 13236 KB Output is correct
85 Correct 77 ms 13132 KB Output is correct
86 Correct 77 ms 13132 KB Output is correct
87 Correct 76 ms 13240 KB Output is correct
88 Correct 76 ms 13132 KB Output is correct
89 Correct 80 ms 13172 KB Output is correct
90 Correct 77 ms 13244 KB Output is correct