답안 #86853

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
86853 2018-11-27T20:43:33 Z KCSC Dango Maker (JOI18_dango_maker) C++14
100 / 100
534 ms 148824 KB
#include <bits/stdc++.h>
using namespace std;

const int DIM = 3109;
const int di[9] = {-2, -2, -2, -1, -1, -1, 0, 0, 0};
const int dj[9] = {0, 1, 2, 0, 1, 2, 0, 1, 2};

char str[DIM][DIM];
pair<short, short> lef[DIM][DIM], rig[DIM][DIM];

bitset<DIM> mrk[DIM], val1[DIM], val2[DIM];

bool match(int x, int y, int &ans) {
	if (mrk[x][y]) {
		return false; }
	mrk[x][y] = true;
	for (int d = 0; d < 9; ++d) {
		int xx = x + di[d], yy = y + dj[d];
		if (xx >= 1 and val2[xx][yy] and rig[xx][yy].first == 0) {
			lef[x][y] = make_pair(xx, yy); 
			rig[xx][yy] = make_pair(x, y); 
			--ans; return true; } }
	for (int d = 0; d < 9; ++d) {
		int xx = x + di[d], yy = y + dj[d];
		if (xx >= 1 and val2[xx][yy] and match(rig[xx][yy].first, rig[xx][yy].second, ans)) {
			lef[x][y] = make_pair(xx, yy); 
			rig[xx][yy] = make_pair(x, y);
			return true; } } 
	return false; }

int main(void) {
#ifdef HOME
	freopen("dango.in", "r", stdin);
	freopen("dango.out", "w", stdout);
#endif
	int n, m; cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		cin >> (str[i] + 1); }
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			if (j + 2 <= m and str[i][j] == 'R' and str[i][j + 1] == 'G' and str[i][j + 2] == 'W') {
				val1[i][j] = true; ++ans; }
			if (i + 2 <= n and str[i][j] == 'R' and str[i + 1][j] == 'G' and str[i + 2][j] == 'W') {
				val2[i][j] = true; ++ans; } } }
	bool ok; do {
		ok = false;
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= m; ++j) {
				if (val1[i][j] and lef[i][j].first == 0 and match(i, j, ans)) {
					ok = true; } } }
	} while (ok);
	cout << ans;
	return 0; }
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 476 KB Output is correct
6 Correct 2 ms 616 KB Output is correct
7 Correct 2 ms 616 KB Output is correct
8 Correct 2 ms 616 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 2 ms 656 KB Output is correct
12 Correct 2 ms 676 KB Output is correct
13 Correct 2 ms 680 KB Output is correct
14 Correct 2 ms 684 KB Output is correct
15 Correct 2 ms 688 KB Output is correct
16 Correct 2 ms 692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 476 KB Output is correct
6 Correct 2 ms 616 KB Output is correct
7 Correct 2 ms 616 KB Output is correct
8 Correct 2 ms 616 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 2 ms 656 KB Output is correct
12 Correct 2 ms 676 KB Output is correct
13 Correct 2 ms 680 KB Output is correct
14 Correct 2 ms 684 KB Output is correct
15 Correct 2 ms 688 KB Output is correct
16 Correct 2 ms 692 KB Output is correct
17 Correct 2 ms 696 KB Output is correct
18 Correct 2 ms 700 KB Output is correct
19 Correct 2 ms 704 KB Output is correct
20 Correct 2 ms 704 KB Output is correct
21 Correct 2 ms 708 KB Output is correct
22 Correct 2 ms 712 KB Output is correct
23 Correct 2 ms 716 KB Output is correct
24 Correct 2 ms 720 KB Output is correct
25 Correct 2 ms 728 KB Output is correct
26 Correct 2 ms 728 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 2 ms 868 KB Output is correct
29 Correct 2 ms 868 KB Output is correct
30 Correct 2 ms 868 KB Output is correct
31 Correct 2 ms 868 KB Output is correct
32 Correct 2 ms 868 KB Output is correct
33 Correct 2 ms 884 KB Output is correct
34 Correct 2 ms 888 KB Output is correct
35 Correct 2 ms 888 KB Output is correct
36 Correct 2 ms 888 KB Output is correct
37 Correct 3 ms 896 KB Output is correct
38 Correct 2 ms 896 KB Output is correct
39 Correct 2 ms 904 KB Output is correct
40 Correct 3 ms 908 KB Output is correct
41 Correct 2 ms 912 KB Output is correct
42 Correct 3 ms 916 KB Output is correct
43 Correct 2 ms 920 KB Output is correct
44 Correct 2 ms 920 KB Output is correct
45 Correct 2 ms 928 KB Output is correct
46 Correct 2 ms 928 KB Output is correct
47 Correct 2 ms 940 KB Output is correct
48 Correct 2 ms 940 KB Output is correct
49 Correct 2 ms 948 KB Output is correct
50 Correct 3 ms 952 KB Output is correct
51 Correct 2 ms 960 KB Output is correct
52 Correct 2 ms 960 KB Output is correct
53 Correct 2 ms 964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 476 KB Output is correct
6 Correct 2 ms 616 KB Output is correct
7 Correct 2 ms 616 KB Output is correct
8 Correct 2 ms 616 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 2 ms 656 KB Output is correct
12 Correct 2 ms 676 KB Output is correct
13 Correct 2 ms 680 KB Output is correct
14 Correct 2 ms 684 KB Output is correct
15 Correct 2 ms 688 KB Output is correct
16 Correct 2 ms 692 KB Output is correct
17 Correct 2 ms 696 KB Output is correct
18 Correct 2 ms 700 KB Output is correct
19 Correct 2 ms 704 KB Output is correct
20 Correct 2 ms 704 KB Output is correct
21 Correct 2 ms 708 KB Output is correct
22 Correct 2 ms 712 KB Output is correct
23 Correct 2 ms 716 KB Output is correct
24 Correct 2 ms 720 KB Output is correct
25 Correct 2 ms 728 KB Output is correct
26 Correct 2 ms 728 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 2 ms 868 KB Output is correct
29 Correct 2 ms 868 KB Output is correct
30 Correct 2 ms 868 KB Output is correct
31 Correct 2 ms 868 KB Output is correct
32 Correct 2 ms 868 KB Output is correct
33 Correct 2 ms 884 KB Output is correct
34 Correct 2 ms 888 KB Output is correct
35 Correct 2 ms 888 KB Output is correct
36 Correct 2 ms 888 KB Output is correct
37 Correct 3 ms 896 KB Output is correct
38 Correct 2 ms 896 KB Output is correct
39 Correct 2 ms 904 KB Output is correct
40 Correct 3 ms 908 KB Output is correct
41 Correct 2 ms 912 KB Output is correct
42 Correct 3 ms 916 KB Output is correct
43 Correct 2 ms 920 KB Output is correct
44 Correct 2 ms 920 KB Output is correct
45 Correct 2 ms 928 KB Output is correct
46 Correct 2 ms 928 KB Output is correct
47 Correct 2 ms 940 KB Output is correct
48 Correct 2 ms 940 KB Output is correct
49 Correct 2 ms 948 KB Output is correct
50 Correct 3 ms 952 KB Output is correct
51 Correct 2 ms 960 KB Output is correct
52 Correct 2 ms 960 KB Output is correct
53 Correct 2 ms 964 KB Output is correct
54 Correct 2 ms 964 KB Output is correct
55 Correct 9 ms 10444 KB Output is correct
56 Correct 3 ms 10444 KB Output is correct
57 Correct 15 ms 13800 KB Output is correct
58 Correct 67 ms 20728 KB Output is correct
59 Correct 515 ms 96152 KB Output is correct
60 Correct 514 ms 105004 KB Output is correct
61 Correct 534 ms 113928 KB Output is correct
62 Correct 2 ms 113928 KB Output is correct
63 Correct 490 ms 122348 KB Output is correct
64 Correct 515 ms 131252 KB Output is correct
65 Correct 523 ms 140028 KB Output is correct
66 Correct 522 ms 148824 KB Output is correct
67 Correct 336 ms 148824 KB Output is correct
68 Correct 338 ms 148824 KB Output is correct
69 Correct 364 ms 148824 KB Output is correct
70 Correct 71 ms 148824 KB Output is correct
71 Correct 92 ms 148824 KB Output is correct
72 Correct 70 ms 148824 KB Output is correct
73 Correct 70 ms 148824 KB Output is correct
74 Correct 71 ms 148824 KB Output is correct
75 Correct 71 ms 148824 KB Output is correct
76 Correct 71 ms 148824 KB Output is correct
77 Correct 70 ms 148824 KB Output is correct
78 Correct 75 ms 148824 KB Output is correct
79 Correct 69 ms 148824 KB Output is correct
80 Correct 71 ms 148824 KB Output is correct
81 Correct 71 ms 148824 KB Output is correct
82 Correct 71 ms 148824 KB Output is correct
83 Correct 71 ms 148824 KB Output is correct
84 Correct 72 ms 148824 KB Output is correct
85 Correct 72 ms 148824 KB Output is correct
86 Correct 69 ms 148824 KB Output is correct
87 Correct 71 ms 148824 KB Output is correct
88 Correct 71 ms 148824 KB Output is correct
89 Correct 71 ms 148824 KB Output is correct
90 Correct 71 ms 148824 KB Output is correct