Submission #41108

# Submission time Handle Problem Language Result Execution time Memory
41108 2018-02-12T19:15:04 Z abeker Dango Maker (JOI18_dango_maker) C++14
33 / 100
2000 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 3e3 + 5;
const int MAXS = 3e6 + 5;
const int INF = 0x3f3f3f3f;

int N, M;
char mat[MAXN][MAXN];
vector <int> E[MAXS];
int match[MAXS], dist[MAXS];
int hor[MAXN][MAXN], ver[MAXN][MAXN];
vector <int> lft, rig, all;

void load() {
	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; i++)
		scanf("%s", mat[i]);
}

bool bfs() {
  queue <int> Q;
  for (auto it : lft)
    if (!match[it]) {
      dist[it] = 0;
      Q.push(it);
    }
    else 
			dist[it] = INF;
  
  dist[0] = INF;
  while (!Q.empty()) {
    int x = Q.front(); 
		Q.pop();
    if (!x)
    	continue;
    for (auto it : E[x]) 
      if (dist[match[it]] == INF) {
        dist[match[it]] = dist[x] + 1;
        Q.push(match[it]);
      }
  }
  
  return dist[0] != INF;
}

bool dfs(int x) {
  if (!x)
  	return true;
  for (auto it : E[x]) 
    if (dist[match[it]] == dist[x] + 1 && dfs(match[it])) {
      match[it] = x;
      match[x] = it;
      return true;
    }
  dist[x] = INF;
  return false;
}

int hopcroft_karp() {
  int matching = 0;
  while (bfs())
    for (auto it : lft)
      matching += !match[it] && dfs(it);
  return matching;
}

int get(int x, int y) {
	return M * x + y + 1;
}

void check_hor(int x, int y) {
	if (y > M - 3)
		return;
	for (int i = 0; i < 3; i++)
		if (mat[x][y + i] != "RGW"[i])
			return;
	lft.push_back(get(x, y));
	for (int i = 0; i < 3; i++)
		hor[x][y + i] = get(x, y);
}

void check_ver(int x, int y) {
	if (x > N - 3)
		return;
	for (int i = 0; i < 3; i++)
		if (mat[x + i][y] != "RGW"[i])
			return;
	rig.push_back(get(x, y));
	for (int i = 0; i < 3; i++)
		ver[x + i][y] = get(x, y);
}

void compress(int &ref) {
	if (ref)
		ref = lower_bound(all.begin(), all.end(), ref) - all.begin() + 1;
}

int solve() {
	for (int i = 0; i < N; i++)
		for (int j = 0; j < M; j++) {
			check_hor(i, j);
			check_ver(i, j);
		}
	
	for (auto it : lft)
		all.push_back(it);
		
	for (auto it : rig)
		all.push_back(it);
	
	sort(all.begin(), all.end());
	
	for (auto &it : lft)
		compress(it);
	
	for (auto &it : rig)
		compress(it);
		
	for (int i = 0; i < N; i++)
		for (int j = 0; j < M; j++) {
			compress(hor[i][j]);
			compress(ver[i][j]);
			if (hor[i][j] && ver[i][j]) 
				E[hor[i][j]].push_back(ver[i][j]);
		}
	
	return all.size() - hopcroft_karp();
}

int main() {
	load();
	printf("%d\n", solve());
	return 0;
}

Compilation message

dango_maker.cpp: In function 'void load()':
dango_maker.cpp:16:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
                       ^
dango_maker.cpp:18:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", mat[i]);
                      ^
# Verdict Execution time Memory Grader output
1 Correct 60 ms 70776 KB Output is correct
2 Correct 62 ms 70776 KB Output is correct
3 Correct 60 ms 70952 KB Output is correct
4 Correct 61 ms 70996 KB Output is correct
5 Correct 62 ms 71056 KB Output is correct
6 Correct 61 ms 71056 KB Output is correct
7 Correct 62 ms 71084 KB Output is correct
8 Correct 60 ms 71112 KB Output is correct
9 Correct 65 ms 71112 KB Output is correct
10 Correct 61 ms 71112 KB Output is correct
11 Correct 62 ms 71112 KB Output is correct
12 Correct 60 ms 71112 KB Output is correct
13 Correct 62 ms 71112 KB Output is correct
14 Correct 62 ms 71112 KB Output is correct
15 Correct 67 ms 71112 KB Output is correct
16 Correct 62 ms 71124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 70776 KB Output is correct
2 Correct 62 ms 70776 KB Output is correct
3 Correct 60 ms 70952 KB Output is correct
4 Correct 61 ms 70996 KB Output is correct
5 Correct 62 ms 71056 KB Output is correct
6 Correct 61 ms 71056 KB Output is correct
7 Correct 62 ms 71084 KB Output is correct
8 Correct 60 ms 71112 KB Output is correct
9 Correct 65 ms 71112 KB Output is correct
10 Correct 61 ms 71112 KB Output is correct
11 Correct 62 ms 71112 KB Output is correct
12 Correct 60 ms 71112 KB Output is correct
13 Correct 62 ms 71112 KB Output is correct
14 Correct 62 ms 71112 KB Output is correct
15 Correct 67 ms 71112 KB Output is correct
16 Correct 62 ms 71124 KB Output is correct
17 Correct 60 ms 71124 KB Output is correct
18 Correct 66 ms 71124 KB Output is correct
19 Correct 63 ms 71260 KB Output is correct
20 Correct 66 ms 71260 KB Output is correct
21 Correct 62 ms 71276 KB Output is correct
22 Correct 64 ms 71276 KB Output is correct
23 Correct 64 ms 71276 KB Output is correct
24 Correct 64 ms 71276 KB Output is correct
25 Correct 64 ms 71276 KB Output is correct
26 Correct 62 ms 71276 KB Output is correct
27 Correct 62 ms 71404 KB Output is correct
28 Correct 63 ms 71404 KB Output is correct
29 Correct 61 ms 71404 KB Output is correct
30 Correct 60 ms 71404 KB Output is correct
31 Correct 60 ms 71404 KB Output is correct
32 Correct 61 ms 71404 KB Output is correct
33 Correct 60 ms 71404 KB Output is correct
34 Correct 61 ms 71404 KB Output is correct
35 Correct 61 ms 71404 KB Output is correct
36 Correct 60 ms 71404 KB Output is correct
37 Correct 71 ms 71404 KB Output is correct
38 Correct 61 ms 71404 KB Output is correct
39 Correct 62 ms 71404 KB Output is correct
40 Correct 63 ms 71404 KB Output is correct
41 Correct 62 ms 71404 KB Output is correct
42 Correct 64 ms 71404 KB Output is correct
43 Correct 61 ms 71404 KB Output is correct
44 Correct 63 ms 71404 KB Output is correct
45 Correct 61 ms 71404 KB Output is correct
46 Correct 61 ms 71404 KB Output is correct
47 Correct 61 ms 71404 KB Output is correct
48 Correct 64 ms 71404 KB Output is correct
49 Correct 61 ms 71404 KB Output is correct
50 Correct 63 ms 71404 KB Output is correct
51 Correct 58 ms 71404 KB Output is correct
52 Correct 62 ms 71404 KB Output is correct
53 Correct 68 ms 71404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 70776 KB Output is correct
2 Correct 62 ms 70776 KB Output is correct
3 Correct 60 ms 70952 KB Output is correct
4 Correct 61 ms 70996 KB Output is correct
5 Correct 62 ms 71056 KB Output is correct
6 Correct 61 ms 71056 KB Output is correct
7 Correct 62 ms 71084 KB Output is correct
8 Correct 60 ms 71112 KB Output is correct
9 Correct 65 ms 71112 KB Output is correct
10 Correct 61 ms 71112 KB Output is correct
11 Correct 62 ms 71112 KB Output is correct
12 Correct 60 ms 71112 KB Output is correct
13 Correct 62 ms 71112 KB Output is correct
14 Correct 62 ms 71112 KB Output is correct
15 Correct 67 ms 71112 KB Output is correct
16 Correct 62 ms 71124 KB Output is correct
17 Correct 60 ms 71124 KB Output is correct
18 Correct 66 ms 71124 KB Output is correct
19 Correct 63 ms 71260 KB Output is correct
20 Correct 66 ms 71260 KB Output is correct
21 Correct 62 ms 71276 KB Output is correct
22 Correct 64 ms 71276 KB Output is correct
23 Correct 64 ms 71276 KB Output is correct
24 Correct 64 ms 71276 KB Output is correct
25 Correct 64 ms 71276 KB Output is correct
26 Correct 62 ms 71276 KB Output is correct
27 Correct 62 ms 71404 KB Output is correct
28 Correct 63 ms 71404 KB Output is correct
29 Correct 61 ms 71404 KB Output is correct
30 Correct 60 ms 71404 KB Output is correct
31 Correct 60 ms 71404 KB Output is correct
32 Correct 61 ms 71404 KB Output is correct
33 Correct 60 ms 71404 KB Output is correct
34 Correct 61 ms 71404 KB Output is correct
35 Correct 61 ms 71404 KB Output is correct
36 Correct 60 ms 71404 KB Output is correct
37 Correct 71 ms 71404 KB Output is correct
38 Correct 61 ms 71404 KB Output is correct
39 Correct 62 ms 71404 KB Output is correct
40 Correct 63 ms 71404 KB Output is correct
41 Correct 62 ms 71404 KB Output is correct
42 Correct 64 ms 71404 KB Output is correct
43 Correct 61 ms 71404 KB Output is correct
44 Correct 63 ms 71404 KB Output is correct
45 Correct 61 ms 71404 KB Output is correct
46 Correct 61 ms 71404 KB Output is correct
47 Correct 61 ms 71404 KB Output is correct
48 Correct 64 ms 71404 KB Output is correct
49 Correct 61 ms 71404 KB Output is correct
50 Correct 63 ms 71404 KB Output is correct
51 Correct 58 ms 71404 KB Output is correct
52 Correct 62 ms 71404 KB Output is correct
53 Correct 68 ms 71404 KB Output is correct
54 Correct 61 ms 71404 KB Output is correct
55 Correct 74 ms 81184 KB Output is correct
56 Correct 64 ms 81184 KB Output is correct
57 Correct 76 ms 89684 KB Output is correct
58 Correct 142 ms 91384 KB Output is correct
59 Correct 736 ms 165764 KB Output is correct
60 Correct 735 ms 165764 KB Output is correct
61 Correct 718 ms 165764 KB Output is correct
62 Correct 61 ms 165764 KB Output is correct
63 Correct 697 ms 165764 KB Output is correct
64 Execution timed out 2066 ms 262144 KB Time limit exceeded
65 Halted 0 ms 0 KB -