답안 #753712

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
753712 2023-06-05T18:18:56 Z nicksms 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
100 / 100
2573 ms 27572 KB
/**
 *      Author:  Nicholas Winschel
 *      Created: 05.10.2023 22:07:36
**/

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using db=long double;
template<class T> using V=vector<T>;
using vi = V<int>;
using vl = V<ll>;
using pi = pair<int,int>;
#define f first
#define s second
#define sz(x) (int)((x).size())

void answer(int X);
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]);

int inf = 1e9+500;

void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
	V<vi> r(2*N);
	vi f(2*N, -1);
	for (int i = 0; i < M; i++) {
		if (f[R[i][0]] == -1 && f[R[i][1]] == -1) {
			f[R[i][0]] = R[i][1]+N;
			f[R[i][1]] = R[i][0]+N;
		} else if (f[R[i][0]] == -1) {
			f[R[i][0]] = R[i][1];
			if (f[R[i][1]+N]==-1) {
				f[R[i][1]+N]=R[i][0]+N;
			}
		} else if (f[R[i][1]] == -1) {
			f[R[i][1]] = R[i][0];
			if (f[R[i][0]+N]==-1) {
				f[R[i][0]+N]=R[i][1]+N;
			}

		} else if (f[R[i][0]+N] == -1 || f[R[i][1]+N]==-1) {
			if (f[R[i][0]+N]==-1) f[R[i][0]+N]=R[i][1];
			if (f[R[i][1]+N]==-1) f[R[i][1]+N]=R[i][0];
		} 
	}
	for (int i = 0; i < N; i++) {
		if (f[i+N]==-1) f[i+N]=f[i];
		r[f[i]].push_back(i);
		r[f[i+N]].push_back(i+N);
	}
	vi ub(2*N, inf), b(2*N,inf);
	V<bool> vis(2*N);
	auto dfs = [&](int v, int c, auto &&dfs) -> int {
		if (vis[v]) return c;
		vis[v]=true;
		ub[v]=c;
		int ret = 0;
		for (int x : r[v]) {
			ret = max(ret, dfs(x,c+1,dfs));
		}
		return ret;
	};
	int cub = dfs(P,0,dfs);
	swap(ub,b);
	vis=V<bool>(2*N);
	int cb = dfs(P+N,0,dfs);
	swap(ub,b);
	for (int i = 0; i < Q; i++) {
		int K = G[i];
		int ans = 0;
		for (int i = 0; i < N; i++) {
			if ((ub[i] <= K && (ub[i] == K || (cub && (K-ub[i])%cub == 0)))
				|| (b[i] <= K && (b[i] == K || (cb && (K-b[i])%cb == 0)))) ans++;
		}
		answer(ans);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 440 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 13 ms 3256 KB Output is correct
12 Correct 19 ms 5332 KB Output is correct
13 Correct 41 ms 17976 KB Output is correct
14 Correct 66 ms 17128 KB Output is correct
15 Correct 98 ms 17544 KB Output is correct
16 Correct 76 ms 12780 KB Output is correct
17 Correct 63 ms 11296 KB Output is correct
18 Correct 19 ms 5300 KB Output is correct
19 Correct 73 ms 17096 KB Output is correct
20 Correct 104 ms 17440 KB Output is correct
21 Correct 71 ms 12772 KB Output is correct
22 Correct 55 ms 11196 KB Output is correct
23 Correct 67 ms 18840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 440 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 13 ms 3256 KB Output is correct
12 Correct 19 ms 5332 KB Output is correct
13 Correct 41 ms 17976 KB Output is correct
14 Correct 66 ms 17128 KB Output is correct
15 Correct 98 ms 17544 KB Output is correct
16 Correct 76 ms 12780 KB Output is correct
17 Correct 63 ms 11296 KB Output is correct
18 Correct 19 ms 5300 KB Output is correct
19 Correct 73 ms 17096 KB Output is correct
20 Correct 104 ms 17440 KB Output is correct
21 Correct 71 ms 12772 KB Output is correct
22 Correct 55 ms 11196 KB Output is correct
23 Correct 67 ms 18840 KB Output is correct
24 Correct 1 ms 264 KB Output is correct
25 Correct 84 ms 3336 KB Output is correct
26 Correct 100 ms 5380 KB Output is correct
27 Correct 2202 ms 18240 KB Output is correct
28 Correct 781 ms 17392 KB Output is correct
29 Correct 2530 ms 17732 KB Output is correct
30 Correct 1394 ms 12908 KB Output is correct
31 Correct 1390 ms 11264 KB Output is correct
32 Correct 98 ms 5392 KB Output is correct
33 Correct 808 ms 17256 KB Output is correct
34 Correct 2573 ms 17580 KB Output is correct
35 Correct 1522 ms 12844 KB Output is correct
36 Correct 1408 ms 11432 KB Output is correct
37 Correct 572 ms 19024 KB Output is correct
38 Correct 1937 ms 27572 KB Output is correct