Submission #303896

# Submission time Handle Problem Language Result Execution time Memory
303896 2020-09-20T18:05:16 Z pit4h Dango Maker (JOI18_dango_maker) C++14
33 / 100
259 ms 262148 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 3001;
int n, m, nr;
int matched[N * N], vis[N * N], rep[N][N];
int iter;
bool horiz[N][N], vert[N][N];
string tab[N];
vector<int> g[N * N];
bool match(int x) {
	vis[x] = iter;
	for(int i: g[x]) {
		if(matched[i] == -1) {
			matched[i] = x;
			return true;
		}
	}
	for(int i: g[x]) {
		if(vis[matched[i]] != iter && match(matched[i])) {
			matched[i] = x;
			return true;
		}
	}
	return false;
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n>>m;
	for(int i=0; i<n; ++i) {
		cin>>tab[i];
	}
	for(int i=0; i<n; ++i) { // left - right
		for(int j=0; j+2<m; ++j) {
			if(tab[i][j] == 'R' && tab[i][j+1] == 'G' && tab[i][j+2] == 'W') {
				vert[i][j] = 1;
			}
		}
	}
	for(int i=0; i+2<n; ++i) { // top - bottom 
		for(int j=0; j<m; ++j) {
			if(tab[i][j] == 'R' && tab[i+1][j] == 'G' && tab[i+2][j] == 'W') {
				horiz[i][j] = 1;
				rep[i][j] = nr;
				nr++;
			}
		}
	}
	int sz = 0;
	for(int i=0; i<n; ++i) {
		for(int j=0; j<m; ++j) {
			if(vert[i][j]) {
				if(horiz[i][j]) {
					g[sz].push_back(rep[i][j]);
				}
				if(i-1>=0 && j+1<m && horiz[i-1][j+1]) {
					g[sz].push_back(rep[i-1][j+1]);
				}
				if(i-2>=0 && j+2<m && horiz[i-2][j+2]) {
					g[sz].push_back(rep[i-2][j+2]);
				}
				sz++;
			}
		}
	}
	for(int i=0; i<nr; ++i) {
		matched[i] = -1;
	}
	int ans = 0;
	for(int i=0; i<sz; ++i) {
		iter++;
		match(i);
	}
	for(int i=0; i<nr; ++i) {
		if(matched[i] != -1) {
			ans++;
		}
	}
	cout<<nr + sz - ans;
}
# Verdict Execution time Memory Grader output
1 Correct 131 ms 211964 KB Output is correct
2 Correct 131 ms 211960 KB Output is correct
3 Correct 130 ms 211960 KB Output is correct
4 Correct 131 ms 211960 KB Output is correct
5 Correct 130 ms 211960 KB Output is correct
6 Correct 130 ms 211960 KB Output is correct
7 Correct 131 ms 211960 KB Output is correct
8 Correct 135 ms 212116 KB Output is correct
9 Correct 131 ms 211960 KB Output is correct
10 Correct 131 ms 211904 KB Output is correct
11 Correct 131 ms 211960 KB Output is correct
12 Correct 129 ms 212012 KB Output is correct
13 Correct 130 ms 211960 KB Output is correct
14 Correct 130 ms 211960 KB Output is correct
15 Correct 131 ms 211960 KB Output is correct
16 Correct 134 ms 211960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 211964 KB Output is correct
2 Correct 131 ms 211960 KB Output is correct
3 Correct 130 ms 211960 KB Output is correct
4 Correct 131 ms 211960 KB Output is correct
5 Correct 130 ms 211960 KB Output is correct
6 Correct 130 ms 211960 KB Output is correct
7 Correct 131 ms 211960 KB Output is correct
8 Correct 135 ms 212116 KB Output is correct
9 Correct 131 ms 211960 KB Output is correct
10 Correct 131 ms 211904 KB Output is correct
11 Correct 131 ms 211960 KB Output is correct
12 Correct 129 ms 212012 KB Output is correct
13 Correct 130 ms 211960 KB Output is correct
14 Correct 130 ms 211960 KB Output is correct
15 Correct 131 ms 211960 KB Output is correct
16 Correct 134 ms 211960 KB Output is correct
17 Correct 131 ms 211960 KB Output is correct
18 Correct 136 ms 211960 KB Output is correct
19 Correct 131 ms 212088 KB Output is correct
20 Correct 134 ms 211960 KB Output is correct
21 Correct 133 ms 211964 KB Output is correct
22 Correct 133 ms 211960 KB Output is correct
23 Correct 133 ms 212088 KB Output is correct
24 Correct 134 ms 211960 KB Output is correct
25 Correct 136 ms 211960 KB Output is correct
26 Correct 134 ms 211960 KB Output is correct
27 Correct 131 ms 212088 KB Output is correct
28 Correct 131 ms 211960 KB Output is correct
29 Correct 128 ms 211960 KB Output is correct
30 Correct 129 ms 211960 KB Output is correct
31 Correct 129 ms 211960 KB Output is correct
32 Correct 128 ms 211964 KB Output is correct
33 Correct 130 ms 212208 KB Output is correct
34 Correct 134 ms 212344 KB Output is correct
35 Correct 131 ms 212088 KB Output is correct
36 Correct 131 ms 211960 KB Output is correct
37 Correct 132 ms 211960 KB Output is correct
38 Correct 132 ms 212120 KB Output is correct
39 Correct 132 ms 211956 KB Output is correct
40 Correct 131 ms 211960 KB Output is correct
41 Correct 134 ms 212088 KB Output is correct
42 Correct 131 ms 212088 KB Output is correct
43 Correct 136 ms 212088 KB Output is correct
44 Correct 131 ms 211960 KB Output is correct
45 Correct 134 ms 211960 KB Output is correct
46 Correct 129 ms 211960 KB Output is correct
47 Correct 129 ms 211960 KB Output is correct
48 Correct 130 ms 211960 KB Output is correct
49 Correct 133 ms 212088 KB Output is correct
50 Correct 130 ms 211960 KB Output is correct
51 Correct 131 ms 211960 KB Output is correct
52 Correct 132 ms 212216 KB Output is correct
53 Correct 129 ms 211960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 211964 KB Output is correct
2 Correct 131 ms 211960 KB Output is correct
3 Correct 130 ms 211960 KB Output is correct
4 Correct 131 ms 211960 KB Output is correct
5 Correct 130 ms 211960 KB Output is correct
6 Correct 130 ms 211960 KB Output is correct
7 Correct 131 ms 211960 KB Output is correct
8 Correct 135 ms 212116 KB Output is correct
9 Correct 131 ms 211960 KB Output is correct
10 Correct 131 ms 211904 KB Output is correct
11 Correct 131 ms 211960 KB Output is correct
12 Correct 129 ms 212012 KB Output is correct
13 Correct 130 ms 211960 KB Output is correct
14 Correct 130 ms 211960 KB Output is correct
15 Correct 131 ms 211960 KB Output is correct
16 Correct 134 ms 211960 KB Output is correct
17 Correct 131 ms 211960 KB Output is correct
18 Correct 136 ms 211960 KB Output is correct
19 Correct 131 ms 212088 KB Output is correct
20 Correct 134 ms 211960 KB Output is correct
21 Correct 133 ms 211964 KB Output is correct
22 Correct 133 ms 211960 KB Output is correct
23 Correct 133 ms 212088 KB Output is correct
24 Correct 134 ms 211960 KB Output is correct
25 Correct 136 ms 211960 KB Output is correct
26 Correct 134 ms 211960 KB Output is correct
27 Correct 131 ms 212088 KB Output is correct
28 Correct 131 ms 211960 KB Output is correct
29 Correct 128 ms 211960 KB Output is correct
30 Correct 129 ms 211960 KB Output is correct
31 Correct 129 ms 211960 KB Output is correct
32 Correct 128 ms 211964 KB Output is correct
33 Correct 130 ms 212208 KB Output is correct
34 Correct 134 ms 212344 KB Output is correct
35 Correct 131 ms 212088 KB Output is correct
36 Correct 131 ms 211960 KB Output is correct
37 Correct 132 ms 211960 KB Output is correct
38 Correct 132 ms 212120 KB Output is correct
39 Correct 132 ms 211956 KB Output is correct
40 Correct 131 ms 211960 KB Output is correct
41 Correct 134 ms 212088 KB Output is correct
42 Correct 131 ms 212088 KB Output is correct
43 Correct 136 ms 212088 KB Output is correct
44 Correct 131 ms 211960 KB Output is correct
45 Correct 134 ms 211960 KB Output is correct
46 Correct 129 ms 211960 KB Output is correct
47 Correct 129 ms 211960 KB Output is correct
48 Correct 130 ms 211960 KB Output is correct
49 Correct 133 ms 212088 KB Output is correct
50 Correct 130 ms 211960 KB Output is correct
51 Correct 131 ms 211960 KB Output is correct
52 Correct 132 ms 212216 KB Output is correct
53 Correct 129 ms 211960 KB Output is correct
54 Correct 128 ms 211960 KB Output is correct
55 Correct 136 ms 212856 KB Output is correct
56 Correct 134 ms 212216 KB Output is correct
57 Correct 140 ms 225272 KB Output is correct
58 Correct 157 ms 227320 KB Output is correct
59 Runtime error 259 ms 262148 KB Execution killed with signal 9
60 Halted 0 ms 0 KB -