제출 #364383

#제출 시각아이디문제언어결과실행 시간메모리
364383Kevin_Zhang_TW우주 해적 (JOI14_space_pirate)C++17
10 / 100
12 ms780 KiB
#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); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#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;
int n, a[MAX_N];
ll way[MAX_N];

ll pf[MAX_N];
ll k;
void addone() {
	vector<int> vis(n+1);
	ll s = k, y = 0;
	int x = 1;
	for (int i = 0;i < s;++i) {
		if (x == a[x]) break;
		vis[x] = i;
		x = a[x];
		if (vis[x]) {
			y = (s - i - 1) % (i + 1 - vis[x]);
			break;
		}
	}
	while (y--) x = a[x];
	++way[x];
}
void brute() {
	for (int i = 1;i <= n;++i) for (int j = 1;j <= n;++j) {
		int old = a[i];
		a[i] = j;
		addone();
		a[i] = old;
	}
	for (int i = 1;i <= n;++i)
		cout << way[i] << '\n';
}
void solve3() {
	vector<int> od(n+1);
	for (int i = 0, x = 1;i < n;++i) {
		od[x] = i;
		x = a[x];
	}
}
int32_t main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> k;
	for (int i = 1;i <= n;++i)
		cin >> a[i];

	if (n <= 100) brute();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...