Submission #638491

#TimeUsernameProblemLanguageResultExecution timeMemory
638491TranGiaHuy1508Permutation (APIO22_perm)C++17
10 / 100
2 ms340 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; namespace { vector<int> primes = {2, 3, 5}; deque<int> q; int lim; void mult(int x){ for (int i = lim + x - 2; i >= lim; i--){ q.push_back(i); } lim += x - 1; } void add1(){ q.push_front(lim++); } bool solve(ll k, int req = 90){ if (lim > req) return false; if (k == 1) return true; for (int i = 0; i < (int)primes.size(); i++){ if (k % primes[i] == 0){ bool success = solve(k / primes[i], req - primes[i] + 1); if (!success) continue; mult(primes[i]); return true; } } solve(k - 1, req - 1); add1(); return true; } } vector<int> construct_permutation(ll k){ lim = 0; solve(k); vector<int> v; while (!q.empty()){ v.push_back(q.front()); q.pop_front(); } return v; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...