답안 #534943

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
534943 2022-03-09T07:42:29 Z shrimb 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
69 / 100
5000 ms 41976 KB
#include "garden.h"
#include "gardenlib.h"
#include"bits/stdc++.h"
using namespace std;

int nxt[150001][2];
int dp[150001][2][32];


void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
	for (int i = 0 ; i < M ; i++) {
		auto [u, v] = R[i];
		u++, v++;
		if (!nxt[u][0] and !nxt[v][0]) {
			nxt[u][0] = -v;
			nxt[v][0] = -u;
		}
		if (!nxt[u][0]) nxt[u][0] = v;
		if (!nxt[v][0]) nxt[v][0] = u;

		if (abs(nxt[u][0]) != v and nxt[u][1] == 0) {
			if (abs(nxt[v][0]) == u) nxt[u][1] = -v;
			else nxt[u][1] = v;
		}

		if (abs(nxt[v][0]) != u and nxt[v][1] == 0) {
			if (abs(nxt[u][0]) == v) nxt[v][1] = -u;
			else nxt[v][1] = u;
		}
	}

	for (int i = 1 ; i <= N ; i++) {
		if (nxt[i][1] == 0) nxt[i][1] = nxt[i][0];
	}

	// for (int i = 1 ; i <= N ; i++) {
	// 	cout << i << ": " << nxt[i][0] << " " << nxt[i][1] << endl;
	// }

	for (int j = 0 ; j < 32 ; j++) {
		for (int i = 1 ; i <= N ; i++) {
			for (int k = 0 ; k < 2 ; k++) {
				if (j == 0) {
					dp[i][k][j] = nxt[i][k];
				} else {
					int x = dp[i][k][j-1];
					int u = abs(x);
					int v = x < 0;
					dp[i][k][j] = dp[u][v][j-1];
				}
			}
		}
	}

	for (int q = 0 ; q < Q ; q++) {
		int k = G[q];
		int ans = 0;
		for (int i = 1 ; i <= N ; i++) {
			int u = i, v = 0;
			for (int j = 31 ; j >= 0 ; j--) {
				if (k & (1 << j)) {
					int x = dp[u][v][j];
					u = abs(x);
					v = x < 0;
				}
			}
			// cerr << q << ": " << i << " " << u << endl;
			if (u == P + 1) {
				ans++;
			}
		}
		answer(ans);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 4 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 4 ms 592 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 22 ms 6380 KB Output is correct
12 Correct 44 ms 10444 KB Output is correct
13 Correct 149 ms 23040 KB Output is correct
14 Correct 152 ms 36360 KB Output is correct
15 Correct 166 ms 38464 KB Output is correct
16 Correct 132 ms 26556 KB Output is correct
17 Correct 101 ms 22660 KB Output is correct
18 Correct 39 ms 10972 KB Output is correct
19 Correct 153 ms 37904 KB Output is correct
20 Correct 158 ms 38340 KB Output is correct
21 Correct 105 ms 26552 KB Output is correct
22 Correct 89 ms 22704 KB Output is correct
23 Correct 212 ms 41976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 4 ms 592 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 22 ms 6380 KB Output is correct
12 Correct 44 ms 10444 KB Output is correct
13 Correct 149 ms 23040 KB Output is correct
14 Correct 152 ms 36360 KB Output is correct
15 Correct 166 ms 38464 KB Output is correct
16 Correct 132 ms 26556 KB Output is correct
17 Correct 101 ms 22660 KB Output is correct
18 Correct 39 ms 10972 KB Output is correct
19 Correct 153 ms 37904 KB Output is correct
20 Correct 158 ms 38340 KB Output is correct
21 Correct 105 ms 26552 KB Output is correct
22 Correct 89 ms 22704 KB Output is correct
23 Correct 212 ms 41976 KB Output is correct
24 Correct 10 ms 332 KB Output is correct
25 Execution timed out 5039 ms 6548 KB Time limit exceeded
26 Halted 0 ms 0 KB -