답안 #345110

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
345110 2021-01-07T03:13:23 Z Kevin_Zhang_TW 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
100 / 100
2978 ms 63340 KB
#include "garden.h"
#include "gardenlib.h"

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a ? (a = b, true) : false; }
template<class T> bool chmax(T &a, T b) { return a < b ? (a = b, true) : false; }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L) == R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
const int MAX_N = 300010, MAX_K = 30, inf = 1e9 + 7;

int nxt[MAX_K][MAX_N], n;
int cur[MAX_N], dp[2][MAX_N], ring[2];
vector<int> rev[MAX_N];
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
	{
		auto nxt0 = nxt[0];
		fill(nxt0, nxt0 + N * 2, -1);
		vector<vector<int>> edge(N);
		for (int i = 0;i < M;++i) {
			int a = R[i][0], b = R[i][1];
			edge[a].pb(b), edge[b].pb(a);
		}
		for (int i = 0;i < N;++i) {
			nxt0[i] = edge[i][0];
			if (i == edge[ nxt0[i] ][0]) nxt0[i] += N;
			nxt0[i + N] = nxt0[i];
			if (edge[i].size() > 1) {
				nxt0[i + N] = edge[i][1];
				if (i == edge[ nxt0[i + N] ][0]) nxt0[i + N] += N;
			}
		}
		for (int i = 0;i < N+N;++i)
			rev[ nxt0[i] ].pb(i);
	}
	auto update = [&](int s, int* dp, int &ringlen) {
		ringlen = inf;
		fill(dp, dp + N + N, inf); dp[s] = 0;
		queue<int> q;
		q.emplace(s);
		vector<int> vis(N + N);
		while (q.size()) {
			int x = q.front(); q.pop();
			for (int u : rev[x]) if (chmin(dp[u], dp[x] + 1))
				q.emplace(u);
		}
		for (int x = s, i = 1;;++i) {
			if (vis[x]++) break;
			//DE(x, nxt[0][x]);
			if (nxt[0][x] == s) {
				ringlen = i;
				break;
			}
			x = nxt[0][x];
		}
		DE(ringlen);
	};
	update(P, dp[0], ring[0]), update(P+N, dp[1], ring[1]);

	for (int d = 1;d < MAX_K;++d)
		for (int i = 0;i < N+N;++i)
			nxt[d][i] = nxt[d-1][ nxt[d-1][i] ];

	for (int i = 0;i < Q;++i) {
		int res = 0, K = G[i];
		auto valid = [&](int s, int to) {
			return K >= dp[to][s] && (K - dp[to][s]) % ring[to] == 0;
		};
		for (int j = 0;j < N;++j) {
			if (valid(j, 0) || valid(j, 1))
				++res;
		}
		answer(res);
	}
}

Compilation message

garden.cpp: In lambda function:
garden.cpp:17:17: warning: statement has no effect [-Wunused-value]
   17 | #define DE(...) 0
      |                 ^
garden.cpp:66:3: note: in expansion of macro 'DE'
   66 |   DE(ringlen);
      |   ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 7916 KB Output is correct
2 Correct 9 ms 7916 KB Output is correct
3 Correct 6 ms 7916 KB Output is correct
4 Correct 6 ms 7660 KB Output is correct
5 Correct 7 ms 7532 KB Output is correct
6 Correct 8 ms 8044 KB Output is correct
7 Correct 6 ms 7660 KB Output is correct
8 Correct 6 ms 7916 KB Output is correct
9 Correct 9 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 7916 KB Output is correct
2 Correct 9 ms 7916 KB Output is correct
3 Correct 6 ms 7916 KB Output is correct
4 Correct 6 ms 7660 KB Output is correct
5 Correct 7 ms 7532 KB Output is correct
6 Correct 8 ms 8044 KB Output is correct
7 Correct 6 ms 7660 KB Output is correct
8 Correct 6 ms 7916 KB Output is correct
9 Correct 9 ms 8172 KB Output is correct
10 Correct 6 ms 7660 KB Output is correct
11 Correct 28 ms 15324 KB Output is correct
12 Correct 44 ms 20860 KB Output is correct
13 Correct 82 ms 38592 KB Output is correct
14 Correct 168 ms 54076 KB Output is correct
15 Correct 221 ms 54808 KB Output is correct
16 Correct 183 ms 40208 KB Output is correct
17 Correct 135 ms 35612 KB Output is correct
18 Correct 59 ms 20860 KB Output is correct
19 Correct 178 ms 54024 KB Output is correct
20 Correct 231 ms 54796 KB Output is correct
21 Correct 172 ms 40324 KB Output is correct
22 Correct 156 ms 35568 KB Output is correct
23 Correct 181 ms 57768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 7916 KB Output is correct
2 Correct 9 ms 7916 KB Output is correct
3 Correct 6 ms 7916 KB Output is correct
4 Correct 6 ms 7660 KB Output is correct
5 Correct 7 ms 7532 KB Output is correct
6 Correct 8 ms 8044 KB Output is correct
7 Correct 6 ms 7660 KB Output is correct
8 Correct 6 ms 7916 KB Output is correct
9 Correct 9 ms 8172 KB Output is correct
10 Correct 6 ms 7660 KB Output is correct
11 Correct 28 ms 15324 KB Output is correct
12 Correct 44 ms 20860 KB Output is correct
13 Correct 82 ms 38592 KB Output is correct
14 Correct 168 ms 54076 KB Output is correct
15 Correct 221 ms 54808 KB Output is correct
16 Correct 183 ms 40208 KB Output is correct
17 Correct 135 ms 35612 KB Output is correct
18 Correct 59 ms 20860 KB Output is correct
19 Correct 178 ms 54024 KB Output is correct
20 Correct 231 ms 54796 KB Output is correct
21 Correct 172 ms 40324 KB Output is correct
22 Correct 156 ms 35568 KB Output is correct
23 Correct 181 ms 57768 KB Output is correct
24 Correct 8 ms 7660 KB Output is correct
25 Correct 107 ms 15452 KB Output is correct
26 Correct 150 ms 20860 KB Output is correct
27 Correct 2641 ms 38632 KB Output is correct
28 Correct 1133 ms 54280 KB Output is correct
29 Correct 2978 ms 54896 KB Output is correct
30 Correct 1720 ms 40380 KB Output is correct
31 Correct 1768 ms 35832 KB Output is correct
32 Correct 160 ms 21116 KB Output is correct
33 Correct 1057 ms 54196 KB Output is correct
34 Correct 2977 ms 54876 KB Output is correct
35 Correct 1784 ms 40372 KB Output is correct
36 Correct 2027 ms 35720 KB Output is correct
37 Correct 847 ms 57836 KB Output is correct
38 Correct 2383 ms 63340 KB Output is correct