Submission #747647

#TimeUsernameProblemLanguageResultExecution timeMemory
747647Dan4LifeSpace Pirate (JOI14_space_pirate)C++17
0 / 100
2 ms852 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int mxN = (int)3e3+10; const int mxLg = 13; const int LINF = (int)1e18+10; int n, k, p[mxN], ans[mxN], vis[mxN], cyc[mxN], SZ[mxN]; int dis[mxN][mxN], jmp[mxLg][mxN]; int getPath(int x, int k){ if(k==0) return x; if(dis[x][cyc[x]] <= k) k-=dis[x][cyc[x]], k%=SZ[cyc[x]], x = cyc[x]; for(int i = 0; i<mxLg; i++) if((k>>i)&1) x = jmp[i][x]; return x; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for(int i = 1; i <= n; i++) cin >> p[i], jmp[0][i]=p[i]; for(int i = 1; i < mxLg; i++) for(int j = 1; j <= n; j++) jmp[i][j] = jmp[i-1][jmp[i-1][j]]; for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) dis[i][j] = LINF; for(int i = 1; i <= n; i++){ int j = i, tot=0; vector<int> v; v.clear(); while(!vis[j]) dis[i][j] = tot++, v.push_back(j), vis[j]=1, j=p[j]; for(auto u : v) cyc[u]=j, vis[u]=0; tot = 0; while(!vis[j]) vis[j]=1, j=p[j], tot++; for(auto u : v) SZ[u] = tot, vis[u]=0; } int def = getPath(1,k); for(int a = 1; a <= n; a++){ for(int b = 1; b <= n; b++){ if(dis[1][a]>=k) ans[def]++; else{ int xd = k-dis[1][a]-1; ans[getPath(b,xd)]++; } } } for(int i = 1; i <= n; i++) cout << ans[i] << "\n"; }

Compilation message (stderr)

space_pirate.cpp: In function 'int32_t main()':
space_pirate.cpp:32:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   32 |   for(auto u : v) cyc[u]=j, vis[u]=0; tot = 0;
      |   ^~~
space_pirate.cpp:32:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   32 |   for(auto u : v) cyc[u]=j, vis[u]=0; tot = 0;
      |                                       ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...