Submission #303882

# Submission time Handle Problem Language Result Execution time Memory
303882 2020-09-20T17:56:00 Z pit4h Dango Maker (JOI18_dango_maker) C++14
33 / 100
146 ms 212856 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<n && horiz[i-1][j+1]) {
					g[sz].push_back(rep[i-1][j+1]);
				}
				if(i-2>=0 && j+2<n && 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 132 ms 211960 KB Output is correct
2 Correct 129 ms 211960 KB Output is correct
3 Correct 128 ms 211960 KB Output is correct
4 Correct 129 ms 212072 KB Output is correct
5 Correct 129 ms 211964 KB Output is correct
6 Correct 134 ms 212088 KB Output is correct
7 Correct 132 ms 212020 KB Output is correct
8 Correct 129 ms 212088 KB Output is correct
9 Correct 131 ms 211960 KB Output is correct
10 Correct 130 ms 212092 KB Output is correct
11 Correct 132 ms 212000 KB Output is correct
12 Correct 129 ms 211960 KB Output is correct
13 Correct 131 ms 211960 KB Output is correct
14 Correct 129 ms 212088 KB Output is correct
15 Correct 131 ms 211960 KB Output is correct
16 Correct 130 ms 211960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 211960 KB Output is correct
2 Correct 129 ms 211960 KB Output is correct
3 Correct 128 ms 211960 KB Output is correct
4 Correct 129 ms 212072 KB Output is correct
5 Correct 129 ms 211964 KB Output is correct
6 Correct 134 ms 212088 KB Output is correct
7 Correct 132 ms 212020 KB Output is correct
8 Correct 129 ms 212088 KB Output is correct
9 Correct 131 ms 211960 KB Output is correct
10 Correct 130 ms 212092 KB Output is correct
11 Correct 132 ms 212000 KB Output is correct
12 Correct 129 ms 211960 KB Output is correct
13 Correct 131 ms 211960 KB Output is correct
14 Correct 129 ms 212088 KB Output is correct
15 Correct 131 ms 211960 KB Output is correct
16 Correct 130 ms 211960 KB Output is correct
17 Correct 129 ms 211960 KB Output is correct
18 Correct 132 ms 211960 KB Output is correct
19 Correct 141 ms 211956 KB Output is correct
20 Correct 129 ms 212000 KB Output is correct
21 Correct 132 ms 212088 KB Output is correct
22 Correct 132 ms 211960 KB Output is correct
23 Correct 131 ms 211964 KB Output is correct
24 Correct 131 ms 211960 KB Output is correct
25 Correct 132 ms 211876 KB Output is correct
26 Correct 131 ms 211872 KB Output is correct
27 Correct 130 ms 212088 KB Output is correct
28 Correct 129 ms 211960 KB Output is correct
29 Correct 129 ms 212080 KB Output is correct
30 Correct 133 ms 211960 KB Output is correct
31 Correct 131 ms 212008 KB Output is correct
32 Correct 132 ms 211960 KB Output is correct
33 Correct 135 ms 211960 KB Output is correct
34 Correct 131 ms 211964 KB Output is correct
35 Correct 133 ms 211960 KB Output is correct
36 Correct 128 ms 211960 KB Output is correct
37 Correct 128 ms 211960 KB Output is correct
38 Correct 126 ms 211960 KB Output is correct
39 Correct 129 ms 211960 KB Output is correct
40 Correct 131 ms 212192 KB Output is correct
41 Correct 133 ms 211972 KB Output is correct
42 Correct 140 ms 211964 KB Output is correct
43 Correct 136 ms 211960 KB Output is correct
44 Correct 137 ms 211960 KB Output is correct
45 Correct 134 ms 212084 KB Output is correct
46 Correct 136 ms 211988 KB Output is correct
47 Correct 138 ms 212140 KB Output is correct
48 Correct 146 ms 212036 KB Output is correct
49 Correct 144 ms 212020 KB Output is correct
50 Correct 135 ms 211960 KB Output is correct
51 Correct 135 ms 211960 KB Output is correct
52 Correct 132 ms 212032 KB Output is correct
53 Correct 138 ms 212104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 211960 KB Output is correct
2 Correct 129 ms 211960 KB Output is correct
3 Correct 128 ms 211960 KB Output is correct
4 Correct 129 ms 212072 KB Output is correct
5 Correct 129 ms 211964 KB Output is correct
6 Correct 134 ms 212088 KB Output is correct
7 Correct 132 ms 212020 KB Output is correct
8 Correct 129 ms 212088 KB Output is correct
9 Correct 131 ms 211960 KB Output is correct
10 Correct 130 ms 212092 KB Output is correct
11 Correct 132 ms 212000 KB Output is correct
12 Correct 129 ms 211960 KB Output is correct
13 Correct 131 ms 211960 KB Output is correct
14 Correct 129 ms 212088 KB Output is correct
15 Correct 131 ms 211960 KB Output is correct
16 Correct 130 ms 211960 KB Output is correct
17 Correct 129 ms 211960 KB Output is correct
18 Correct 132 ms 211960 KB Output is correct
19 Correct 141 ms 211956 KB Output is correct
20 Correct 129 ms 212000 KB Output is correct
21 Correct 132 ms 212088 KB Output is correct
22 Correct 132 ms 211960 KB Output is correct
23 Correct 131 ms 211964 KB Output is correct
24 Correct 131 ms 211960 KB Output is correct
25 Correct 132 ms 211876 KB Output is correct
26 Correct 131 ms 211872 KB Output is correct
27 Correct 130 ms 212088 KB Output is correct
28 Correct 129 ms 211960 KB Output is correct
29 Correct 129 ms 212080 KB Output is correct
30 Correct 133 ms 211960 KB Output is correct
31 Correct 131 ms 212008 KB Output is correct
32 Correct 132 ms 211960 KB Output is correct
33 Correct 135 ms 211960 KB Output is correct
34 Correct 131 ms 211964 KB Output is correct
35 Correct 133 ms 211960 KB Output is correct
36 Correct 128 ms 211960 KB Output is correct
37 Correct 128 ms 211960 KB Output is correct
38 Correct 126 ms 211960 KB Output is correct
39 Correct 129 ms 211960 KB Output is correct
40 Correct 131 ms 212192 KB Output is correct
41 Correct 133 ms 211972 KB Output is correct
42 Correct 140 ms 211964 KB Output is correct
43 Correct 136 ms 211960 KB Output is correct
44 Correct 137 ms 211960 KB Output is correct
45 Correct 134 ms 212084 KB Output is correct
46 Correct 136 ms 211988 KB Output is correct
47 Correct 138 ms 212140 KB Output is correct
48 Correct 146 ms 212036 KB Output is correct
49 Correct 144 ms 212020 KB Output is correct
50 Correct 135 ms 211960 KB Output is correct
51 Correct 135 ms 211960 KB Output is correct
52 Correct 132 ms 212032 KB Output is correct
53 Correct 138 ms 212104 KB Output is correct
54 Correct 139 ms 211996 KB Output is correct
55 Correct 143 ms 212856 KB Output is correct
56 Incorrect 141 ms 212152 KB Output isn't correct
57 Halted 0 ms 0 KB -