답안 #207530

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
207530 2020-03-07T18:33:22 Z mode149256 Dango Maker (JOI18_dango_maker) C++14
100 / 100
1176 ms 9868 KB
/*input
4 4
RGRR
RRRG
GRGW
RGWW


5 5
RGRGW
GRRGW
WGGWR
RWRGW
RGWGW

3 4
RGWR
GRGG
RGWW

4 4
RGWR
GRRG
WGGW
WWWR
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;

#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"

const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;

template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }

template<typename T>
void print(vector<T> vec, string name = "") {
	cout << name;
	for (auto u : vec)
		cout << u << ' ';
	cout << '\n';
}

using vc = vector<char>;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int N, M;
	cin >> N >> M;

	vector<vc> sk(N, vc(M));

	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < M; ++j)
		{
			cin >> sk[i][j];
		}
	}

	vii dp;

	// 0 - nieko
	// 1 - vertical
	// 2 - horizontal
	ll ats = 0;

	auto ver = [&](int i, int j) -> int {
		return i - 1 >= 0 and i + 1 < N and sk[i - 1][j] == 'R'
		and sk[i][j] == 'G' and sk[i + 1][j] == 'W';
	};

	auto hor = [&](int i, int j) -> int {
		return j - 1 >= 0 and j + 1 < M and sk[i][j - 1] == 'R'
		and sk[i][j] == 'G' and sk[i][j + 1] == 'W';
	};

	for (int d = 0; d < N + M - 1; ++d)
	{
		dp = vii(N, vi(3, 0));
		int lst;
		for (int i = max(d - M + 1, 0); i < N; i++)
		{
			int j = d - i;
			if (j < 0) break;

			dp[i][0] = (i ? max({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]}) : 0);
			dp[i][1] = (i ? max(dp[i - 1][0], dp[i - 1][1]) : 0) + ver(i, j);
			dp[i][2] = (i ? max(dp[i - 1][0], dp[i - 1][2]) : 0) + hor(i, j);
			lst = i;
		}

		ats += max({dp[lst][0], dp[lst][1], dp[lst][2]});
	}

	printf("%lld\n", ats);
}

/* Look for:
* special cases (n=1?)
* overflow (ll vs int?)
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* array bounds
*/

Compilation message

dango_maker.cpp: In function 'int main()':
dango_maker.cpp:128:21: warning: 'lst' may be used uninitialized in this function [-Wmaybe-uninitialized]
   ats += max({dp[lst][0], dp[lst][1], dp[lst][2]});
                     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 248 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 4 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 248 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 4 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 4 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 4 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 380 KB Output is correct
26 Correct 5 ms 248 KB Output is correct
27 Correct 6 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 372 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 6 ms 376 KB Output is correct
37 Correct 5 ms 376 KB Output is correct
38 Correct 5 ms 376 KB Output is correct
39 Correct 5 ms 376 KB Output is correct
40 Correct 5 ms 376 KB Output is correct
41 Correct 5 ms 376 KB Output is correct
42 Correct 5 ms 376 KB Output is correct
43 Correct 5 ms 376 KB Output is correct
44 Correct 5 ms 376 KB Output is correct
45 Correct 4 ms 376 KB Output is correct
46 Correct 5 ms 376 KB Output is correct
47 Correct 5 ms 376 KB Output is correct
48 Correct 5 ms 376 KB Output is correct
49 Correct 6 ms 376 KB Output is correct
50 Correct 5 ms 376 KB Output is correct
51 Correct 5 ms 376 KB Output is correct
52 Correct 5 ms 376 KB Output is correct
53 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 248 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 4 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 4 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 4 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 380 KB Output is correct
26 Correct 5 ms 248 KB Output is correct
27 Correct 6 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 372 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 6 ms 376 KB Output is correct
37 Correct 5 ms 376 KB Output is correct
38 Correct 5 ms 376 KB Output is correct
39 Correct 5 ms 376 KB Output is correct
40 Correct 5 ms 376 KB Output is correct
41 Correct 5 ms 376 KB Output is correct
42 Correct 5 ms 376 KB Output is correct
43 Correct 5 ms 376 KB Output is correct
44 Correct 5 ms 376 KB Output is correct
45 Correct 4 ms 376 KB Output is correct
46 Correct 5 ms 376 KB Output is correct
47 Correct 5 ms 376 KB Output is correct
48 Correct 5 ms 376 KB Output is correct
49 Correct 6 ms 376 KB Output is correct
50 Correct 5 ms 376 KB Output is correct
51 Correct 5 ms 376 KB Output is correct
52 Correct 5 ms 376 KB Output is correct
53 Correct 5 ms 376 KB Output is correct
54 Correct 5 ms 376 KB Output is correct
55 Correct 418 ms 872 KB Output is correct
56 Correct 6 ms 376 KB Output is correct
57 Correct 190 ms 632 KB Output is correct
58 Correct 127 ms 1500 KB Output is correct
59 Correct 1156 ms 9728 KB Output is correct
60 Correct 1135 ms 9696 KB Output is correct
61 Correct 1150 ms 9676 KB Output is correct
62 Correct 6 ms 376 KB Output is correct
63 Correct 1104 ms 9832 KB Output is correct
64 Correct 1078 ms 9796 KB Output is correct
65 Correct 1096 ms 9788 KB Output is correct
66 Correct 1084 ms 9732 KB Output is correct
67 Correct 1176 ms 9868 KB Output is correct
68 Correct 1081 ms 9764 KB Output is correct
69 Correct 1087 ms 9860 KB Output is correct
70 Correct 119 ms 1400 KB Output is correct
71 Correct 116 ms 1400 KB Output is correct
72 Correct 113 ms 1400 KB Output is correct
73 Correct 113 ms 1400 KB Output is correct
74 Correct 116 ms 1400 KB Output is correct
75 Correct 116 ms 1400 KB Output is correct
76 Correct 116 ms 1404 KB Output is correct
77 Correct 113 ms 1400 KB Output is correct
78 Correct 117 ms 1528 KB Output is correct
79 Correct 113 ms 1528 KB Output is correct
80 Correct 114 ms 1400 KB Output is correct
81 Correct 114 ms 1400 KB Output is correct
82 Correct 123 ms 1400 KB Output is correct
83 Correct 115 ms 1400 KB Output is correct
84 Correct 124 ms 1528 KB Output is correct
85 Correct 113 ms 1528 KB Output is correct
86 Correct 125 ms 1540 KB Output is correct
87 Correct 114 ms 1500 KB Output is correct
88 Correct 119 ms 1400 KB Output is correct
89 Correct 116 ms 1400 KB Output is correct
90 Correct 115 ms 1400 KB Output is correct