#include <bits/stdc++.h>
template <class T>
using Vec = std::vector<T>;
using ll = long long;
constexpr ll INF = std::numeric_limits<ll>::max();
int main() {
int N;
ll K;
std::cin >> N >> K;
Vec<int> A(N);
for (auto &x: A) {
std::cin >> x;
x -= 1;
}
if (N <= 3000) {
Vec<Vec<int>> goes(N);
Vec<Vec<ll>> ord(N, Vec<ll>(N, INF));
for (int u = 0; u < N; ++u) {
ord[u][u] = 0;
goes[u].push_back(u);
while (ord[u][A[goes[u].back()]] == INF) {
const auto v = A[goes[u].back()];
const auto k = (int) goes[u].size();
ord[u][v] = k;
goes[u].push_back(v);
}
}
const auto last = [&](const int u) {
return goes[u].back();
};
const auto connects = [&](const int u) {
return A[last(u)];
};
const auto loop = [&](const int u) {
return ord[u][last(u)] - ord[u][connects(u)] + 1;
};
const auto kth = [&](const int u, const ll k) {
if (k < (int) goes[u].size()) {
return goes[u][k];
}
else {
const auto rem = (k - (int) goes[u].size()) % loop(u);
return goes[u][ord[u][connects(u)] + rem];
}
};
Vec<int> ans(N);
for (int a = 0; a < N; ++a) {
for (int b = 0; b < N; ++b) {
if (ord[0][a] >= K) {
ans[kth(0, K)] += 1;
}
else {
const auto rem = K - ord[0][a] - 1;
if (ord[b][a] >= rem) {
ans[kth(b, rem)] += 1;
}
else {
const auto idx = (rem - ord[b][a] - 1) % (ord[b][a] + 1);
ans[kth(b, idx)] += 1;
}
}
}
}
for (const auto x: ans) {
std::cout << x << '\n';
}
}
else {
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
327 ms |
72176 KB |
Output is correct |
16 |
Correct |
280 ms |
70980 KB |
Output is correct |
17 |
Correct |
320 ms |
72512 KB |
Output is correct |
18 |
Correct |
1783 ms |
114624 KB |
Output is correct |
19 |
Correct |
1074 ms |
94976 KB |
Output is correct |
20 |
Correct |
965 ms |
99380 KB |
Output is correct |
21 |
Correct |
1725 ms |
95760 KB |
Output is correct |
22 |
Correct |
837 ms |
86636 KB |
Output is correct |
23 |
Correct |
1276 ms |
94496 KB |
Output is correct |
24 |
Correct |
666 ms |
84168 KB |
Output is correct |
25 |
Correct |
289 ms |
71728 KB |
Output is correct |
26 |
Correct |
1636 ms |
115812 KB |
Output is correct |
27 |
Correct |
740 ms |
80364 KB |
Output is correct |
28 |
Correct |
756 ms |
83908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
1220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
327 ms |
72176 KB |
Output is correct |
16 |
Correct |
280 ms |
70980 KB |
Output is correct |
17 |
Correct |
320 ms |
72512 KB |
Output is correct |
18 |
Correct |
1783 ms |
114624 KB |
Output is correct |
19 |
Correct |
1074 ms |
94976 KB |
Output is correct |
20 |
Correct |
965 ms |
99380 KB |
Output is correct |
21 |
Correct |
1725 ms |
95760 KB |
Output is correct |
22 |
Correct |
837 ms |
86636 KB |
Output is correct |
23 |
Correct |
1276 ms |
94496 KB |
Output is correct |
24 |
Correct |
666 ms |
84168 KB |
Output is correct |
25 |
Correct |
289 ms |
71728 KB |
Output is correct |
26 |
Correct |
1636 ms |
115812 KB |
Output is correct |
27 |
Correct |
740 ms |
80364 KB |
Output is correct |
28 |
Correct |
756 ms |
83908 KB |
Output is correct |
29 |
Incorrect |
29 ms |
1220 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |