답안 #24886

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
24886 2017-06-16T20:45:56 Z Hiasat 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
69 / 100
218 ms 33696 KB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

const int MX = 150011;
vector<int> adj[MX * 2], g[MX * 2];

int need[MX * 2][2];

void connect(int u , int v, int N) {
	if (adj[u][0] == v || adj[u][0] == v - N)
		u = u + N;
	//cout << "CONNECT " << u << " " << v << endl;
	g[u].push_back(v);
}
void dfs(int u , int cost, int it) {
	if (need[u][it] != -1)
		return;
	if (cost)
		need[u][it] = cost;
	for (int i = 0; i < g[u].size(); ++i) {
		dfs(g[u][i], cost + 1, it);
	}
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
	memset(need, -1, sizeof need);
	for (int i = 0; i < M; ++i) {
		adj[R[i][0]].push_back(R[i][1]);
		adj[R[i][1]].push_back(R[i][0]);
	}
	for (int i = 0; i < N; ++i) {
		while (adj[i].size() > 2)
			adj[i].pop_back();
		if (adj[i].size())
			connect(adj[i][0], i, N);
		if (adj[i].size()) {
			if (adj[i].size() == 2) {
				connect(adj[i][1], i + N, N);
			} else {
				connect(adj[i][0], i + N, N);
			}
		}
	}
	for (int i = 0; i < N; ++i){
		if(adj[i].size() == 0)
			adj[i].push_back(i+N);
	}
	dfs(P, 0, 0);
	dfs(P + N, 0, 1);
/*	for (int i = 0; i < N; ++i){
		printf("%d = %d %d\n",i,need[i][0],need[i][1] );
	}*/
	for (int k = 0 ; k < Q ; k++) {
		int res = 0;
		for (int i = 0; i < N; ++i) {
			for (int it = 0 ; it < 2 ; it++) {
				if(need[i][it] == -1)
					continue;
				int rem = G[k];
				if(rem < need[i][it])
					continue;
				rem -= need[i][it];

				if(rem == 0 || (need[P+it*N][it] != -1 && rem%need[P+it*N][it] == 0)){
					res++;
				}
			}
		}
		answer(res);
	}
}


Compilation message

garden.cpp: In function 'void dfs(int, int, int)':
garden.cpp:25:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < g[u].size(); ++i) {
                  ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 16896 KB Output is correct
2 Correct 18 ms 16900 KB Output is correct
3 Correct 18 ms 16864 KB Output is correct
4 Correct 18 ms 16760 KB Output is correct
5 Correct 18 ms 16732 KB Output is correct
6 Correct 18 ms 16988 KB Output is correct
7 Correct 17 ms 16812 KB Output is correct
8 Correct 18 ms 16860 KB Output is correct
9 Correct 19 ms 17044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 16896 KB Output is correct
2 Correct 18 ms 16900 KB Output is correct
3 Correct 18 ms 16864 KB Output is correct
4 Correct 18 ms 16760 KB Output is correct
5 Correct 18 ms 16732 KB Output is correct
6 Correct 18 ms 16988 KB Output is correct
7 Correct 17 ms 16812 KB Output is correct
8 Correct 18 ms 16860 KB Output is correct
9 Correct 19 ms 17044 KB Output is correct
10 Correct 18 ms 16732 KB Output is correct
11 Correct 31 ms 18808 KB Output is correct
12 Correct 51 ms 19996 KB Output is correct
13 Correct 75 ms 33696 KB Output is correct
14 Correct 181 ms 27388 KB Output is correct
15 Correct 215 ms 27476 KB Output is correct
16 Correct 163 ms 24536 KB Output is correct
17 Correct 157 ms 23564 KB Output is correct
18 Correct 60 ms 19884 KB Output is correct
19 Correct 181 ms 26880 KB Output is correct
20 Correct 218 ms 27080 KB Output is correct
21 Correct 177 ms 24576 KB Output is correct
22 Correct 155 ms 23672 KB Output is correct
23 Correct 173 ms 28000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 16896 KB Output is correct
2 Correct 18 ms 16900 KB Output is correct
3 Correct 18 ms 16864 KB Output is correct
4 Correct 18 ms 16760 KB Output is correct
5 Correct 18 ms 16732 KB Output is correct
6 Correct 18 ms 16988 KB Output is correct
7 Correct 17 ms 16812 KB Output is correct
8 Correct 18 ms 16860 KB Output is correct
9 Correct 19 ms 17044 KB Output is correct
10 Correct 18 ms 16732 KB Output is correct
11 Correct 31 ms 18808 KB Output is correct
12 Correct 51 ms 19996 KB Output is correct
13 Correct 75 ms 33696 KB Output is correct
14 Correct 181 ms 27388 KB Output is correct
15 Correct 215 ms 27476 KB Output is correct
16 Correct 163 ms 24536 KB Output is correct
17 Correct 157 ms 23564 KB Output is correct
18 Correct 60 ms 19884 KB Output is correct
19 Correct 181 ms 26880 KB Output is correct
20 Correct 218 ms 27080 KB Output is correct
21 Correct 177 ms 24576 KB Output is correct
22 Correct 155 ms 23672 KB Output is correct
23 Correct 173 ms 28000 KB Output is correct
24 Incorrect 19 ms 16796 KB Output isn't correct
25 Halted 0 ms 0 KB -