# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
295511 | patrikpavic2 | Space Pirate (JOI14_space_pirate) | C++17 | 1190 ms | 100164 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <cstring>
#include <vector>
#define X first
#define Y second
#define PB push_back
using namespace std;
typedef long long ll;
const int N = 3e3 + 50;
const int LOG = 62;
int dis[N][N], udem[N], kor[N][N];
int bio[N], cnt[N], P[N], klsk, cik[N];
int n;
ll k;
void precompute(int x){
memset(bio, 0, sizeof(bio));
int cur = x, cdis = 0;
while(!bio[cur]){
kor[x][cdis] = cur;
bio[cur] = 1;
dis[x][cur] = cdis++;
cur = P[cur];
}
udem[x] = cur;
if(cur == x)
cik[x] = cdis;
}
int main(){
memset(dis, -1, sizeof(dis));
scanf("%d%lld", &n, &k);
for(int i = 1;i <= n;i++)
scanf("%d", P + i);
for(int i = 1;i <= n;i++)
precompute(i);
int koji_kl = (k - dis[1][udem[1]]) % cik[udem[1]];
klsk = kor[udem[1]][koji_kl];
for(int a = 1;a <= n;a++){
for(int b = 1;b <= n;b++){
if(dis[1][a] == -1){
cnt[klsk]++;
continue;
}
if(dis[b][a] != -1){
int koji = (k - dis[1][a]) % (dis[b][a] + 1);
if(koji == 0)
cnt[a]++;
else
cnt[kor[b][koji - 1]]++;
}
else{
int koji = (k - dis[1][a] - 1 - dis[b][udem[b]]) % cik[udem[b]];
cnt[kor[udem[b]][koji]]++;
}
}
}
for(int i = 1;i <= n;i++)
printf("%d\n", cnt[i]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |