답안 #208844

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
208844 2020-03-12T09:47:28 Z Siberian Dango Maker (JOI18_dango_maker) C++14
100 / 100
461 ms 18296 KB
//#pragma GCC optimize("no-stack-protector")
//#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}

const int MAXN = 3001;
char table[MAXN][MAXN];
vector<int> g[MAXN];
int n, m;

void read() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> table[i][j];
		}
	}
}

bool check_right(int i, int j) {
	return j >= 0 && j + 2 < m && i >= 0 && i < n && table[i][j] == 'R' && table[i][j + 1] == 'G' && table[i][j + 2] == 'W';
}

bool check_down(int i, int j) {
	return j >= 0 && j < m && i >= 0 && i + 2 < n && table[i][j] == 'R' && table[i + 1][j] == 'G' && table[i + 2][j] == 'W';
}

int cnt;

int used[MAXN];
int mt[MAXN];

bool dfs(int v, int c) {
	if (used[v] == c) return false;
	used[v] = c;
	for (auto i : g[v]) {
		if (mt[i] == -1) {
			mt[i] = v;
			return true;
		}
	}

	for (auto i : g[v]) {
		if (dfs(mt[i], c)) {
			mt[i] = v;
			return true;
		}
	}
	return false;
} 


void build() {
	cnt = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cnt += check_right(i, j);
			cnt += check_down(i, j);
		}
	}
}

int ans;

void calc(int s) {
	int i = 0;
	int j = s;
	if (j >= m) {
		j = m - 1;
		i = s - (m - 1);
	}
	int pos = 0;
	for (; i < n && j >= 0; i++, j--, pos++) {
		if (!check_down(i, j)) continue;
		if (check_right(i, j)) {
			g[pos].push_back(pos);
		}
		if(check_right(i + 1, j - 1)) {
			g[pos].push_back(pos + 1);
		}
		if (check_right(i + 2, j - 2)) {
			g[pos].push_back(pos + 2);
		}
	}

	for (int i = 0; i < pos; i++) {
		mt[i] = used[i] = -1;
	}
	int c = 0;
	for (int i = 0; i < pos; i++) {
		dfs(i, c++);
	}
	for (int i = 0; i < pos; i++) {
		if (mt[i] != -1) {
			ans--;
		}
	}
	for (int i = 0; i < pos; i++)
		g[i].clear();
}

void run() {
	build();
	ans = cnt;
	for (int i = 0; i < n + m - 1; i++)
		calc(i);
}

void write() {
	cout << ans << endl;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 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 504 KB Output is correct
8 Correct 5 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 376 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 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 4 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 504 KB Output is correct
8 Correct 5 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 376 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 504 KB Output is correct
20 Correct 5 ms 504 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
26 Correct 5 ms 504 KB Output is correct
27 Correct 5 ms 504 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 504 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 632 KB Output is correct
36 Correct 5 ms 504 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 4 ms 376 KB Output is correct
44 Correct 5 ms 376 KB Output is correct
45 Correct 5 ms 376 KB Output is correct
46 Correct 5 ms 504 KB Output is correct
47 Correct 5 ms 504 KB Output is correct
48 Correct 5 ms 376 KB Output is correct
49 Correct 5 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 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 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 504 KB Output is correct
8 Correct 5 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 376 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 504 KB Output is correct
20 Correct 5 ms 504 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
26 Correct 5 ms 504 KB Output is correct
27 Correct 5 ms 504 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 504 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 632 KB Output is correct
36 Correct 5 ms 504 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 4 ms 376 KB Output is correct
44 Correct 5 ms 376 KB Output is correct
45 Correct 5 ms 376 KB Output is correct
46 Correct 5 ms 504 KB Output is correct
47 Correct 5 ms 504 KB Output is correct
48 Correct 5 ms 376 KB Output is correct
49 Correct 5 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 504 KB Output is correct
54 Correct 5 ms 376 KB Output is correct
55 Correct 9 ms 9208 KB Output is correct
56 Correct 5 ms 376 KB Output is correct
57 Correct 10 ms 6268 KB Output is correct
58 Correct 58 ms 3428 KB Output is correct
59 Correct 438 ms 18168 KB Output is correct
60 Correct 442 ms 18168 KB Output is correct
61 Correct 461 ms 18168 KB Output is correct
62 Correct 5 ms 380 KB Output is correct
63 Correct 442 ms 17784 KB Output is correct
64 Correct 367 ms 18296 KB Output is correct
65 Correct 372 ms 18296 KB Output is correct
66 Correct 382 ms 18296 KB Output is correct
67 Correct 352 ms 18168 KB Output is correct
68 Correct 374 ms 18040 KB Output is correct
69 Correct 369 ms 18044 KB Output is correct
70 Correct 42 ms 4344 KB Output is correct
71 Correct 46 ms 4472 KB Output is correct
72 Correct 44 ms 4472 KB Output is correct
73 Correct 43 ms 4380 KB Output is correct
74 Correct 44 ms 4344 KB Output is correct
75 Correct 45 ms 4344 KB Output is correct
76 Correct 45 ms 4344 KB Output is correct
77 Correct 47 ms 4344 KB Output is correct
78 Correct 45 ms 4472 KB Output is correct
79 Correct 45 ms 4344 KB Output is correct
80 Correct 45 ms 4344 KB Output is correct
81 Correct 44 ms 4344 KB Output is correct
82 Correct 45 ms 4344 KB Output is correct
83 Correct 49 ms 4472 KB Output is correct
84 Correct 45 ms 4344 KB Output is correct
85 Correct 45 ms 4344 KB Output is correct
86 Correct 45 ms 4344 KB Output is correct
87 Correct 45 ms 4344 KB Output is correct
88 Correct 46 ms 4344 KB Output is correct
89 Correct 45 ms 4368 KB Output is correct
90 Correct 48 ms 4472 KB Output is correct