#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = (int) 1e5 + 7;
int n;
int nxt[N];
bool vis[N];
ll solution[N];
ll k;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
//freopen ("input", "r", stdin);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> nxt[i];
}
for (int a = 1; a <= n; a++) {
int init = nxt[a];
for (int b = 1; b <= n; b++) {
for (int i = 1; i <= n; i++) {
vis[i] = 0;
}
vector<int> path, cycle;
nxt[a] = b;
int current = 1;
ll need = 0;
for (ll step = 1; step <= k; step++) {
if (!vis[current]) {
vis[current] = 1;
path.push_back(current);
} else {
need = k - step + 1;
assert(need > 0);
bool has = 0;
for (auto &x : path) {
if (x == current) {
has = 1;
}
if (has) {
cycle.push_back(x);
}
}
break;
}
current = nxt[current];
}
/**
1 2 3
**/
if (need) {
need %= (int) cycle.size();
for (int step = 1; step <= need; step++) {
current = nxt[current];
}
}
solution[current]++;
}
nxt[a] = init;
}
for (int i = 1; i <= n; i++) {
cout << solution[i] << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
5 ms |
320 KB |
Output is correct |
3 |
Correct |
2 ms |
204 KB |
Output is correct |
4 |
Correct |
10 ms |
316 KB |
Output is correct |
5 |
Correct |
8 ms |
304 KB |
Output is correct |
6 |
Correct |
8 ms |
336 KB |
Output is correct |
7 |
Correct |
11 ms |
344 KB |
Output is correct |
8 |
Correct |
8 ms |
324 KB |
Output is correct |
9 |
Correct |
8 ms |
316 KB |
Output is correct |
10 |
Correct |
6 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
10 ms |
332 KB |
Output is correct |
13 |
Correct |
6 ms |
204 KB |
Output is correct |
14 |
Correct |
7 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
5 ms |
320 KB |
Output is correct |
3 |
Correct |
2 ms |
204 KB |
Output is correct |
4 |
Correct |
10 ms |
316 KB |
Output is correct |
5 |
Correct |
8 ms |
304 KB |
Output is correct |
6 |
Correct |
8 ms |
336 KB |
Output is correct |
7 |
Correct |
11 ms |
344 KB |
Output is correct |
8 |
Correct |
8 ms |
324 KB |
Output is correct |
9 |
Correct |
8 ms |
316 KB |
Output is correct |
10 |
Correct |
6 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
10 ms |
332 KB |
Output is correct |
13 |
Correct |
6 ms |
204 KB |
Output is correct |
14 |
Correct |
7 ms |
204 KB |
Output is correct |
15 |
Execution timed out |
2089 ms |
348 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2085 ms |
1592 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
5 ms |
320 KB |
Output is correct |
3 |
Correct |
2 ms |
204 KB |
Output is correct |
4 |
Correct |
10 ms |
316 KB |
Output is correct |
5 |
Correct |
8 ms |
304 KB |
Output is correct |
6 |
Correct |
8 ms |
336 KB |
Output is correct |
7 |
Correct |
11 ms |
344 KB |
Output is correct |
8 |
Correct |
8 ms |
324 KB |
Output is correct |
9 |
Correct |
8 ms |
316 KB |
Output is correct |
10 |
Correct |
6 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
10 ms |
332 KB |
Output is correct |
13 |
Correct |
6 ms |
204 KB |
Output is correct |
14 |
Correct |
7 ms |
204 KB |
Output is correct |
15 |
Execution timed out |
2089 ms |
348 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |