Submission #364382

#TimeUsernameProblemLanguageResultExecution timeMemory
364382Kevin_Zhang_TWSpace Pirate (JOI14_space_pirate)C++17
0 / 100
50 ms5996 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) % (i - 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(); if (set<int>(a+1, a+n+1).size() == n) solve3(); }

Compilation message (stderr)

space_pirate.cpp: In function 'int32_t main()':
space_pirate.cpp:65:34: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   65 |  if (set<int>(a+1, a+n+1).size() == n)
      |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...