Submission #1201726

#TimeUsernameProblemLanguageResultExecution timeMemory
1201726adiyerPermutation (APIO22_perm)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; void add(vector < int > &v, int pos, int x){ vector < int > nw; for(ll i = 0; i < pos; i++) nw.push_back(v[i]); nw.push_back(x); for(ll i = pos; i < v.size(); i++) nw.push_back(v[i]); v = nw; } vector < ll > calc(vector < int > &v) { vector < ll > dp(v.size() + 1, 0); dp[0] = 1; for(int x : v) for(int i = 0; i <= x; i++) dp[x + 1] += dp[i]; return dp; } vector < int > construct_permutation(ll k){ ll x = 0, s = 0, y = 1, f = 0; vector < int > ans; while(1){ if(s) f = 3; else f = 4; y *= f; if(y > k) break; if(f == 3){ ans.push_back(x + 1); ans.push_back(x); x += 2; } else{ ans.push_back(x + 2); ans.push_back(x + 1); ans.push_back(x); x += 3; } } while(1){ ll sum = 0, pos = 1; vector < ll > dp = calc(ans); for(ll val : dp) sum += val; if(sum == k) break; for(ll i = 0; i < dp.size(); i++){ if(sum + dp[i] <= k){ pos = i; sum += dp[i]; } } add(ans, pos, x++); } return ans; } static long long MX = 1e18; static bool check_permutation(vector<int> v) { sort(v.begin(),v.end()); for(int i=0;i<v.size();i++) if(v[i]!=i) return 0; return 1; } long long count_increasing(const vector<int>& v) { vector<long long> dp(v.size() + 1, 0); dp[0] = 1; for (int x : v) { for (int i = 0; i <= x; i++) { dp[x+1] += dp[i]; dp[x+1] = min(dp[x+1],MX+1); } } long long result = 0; for (int i = 0; i <= (int)v.size(); i++){ result += dp[i]; result = min(result,MX+1); } return result; } int main() { int t; assert(1 == scanf("%d", &t)); while(t--) { long long k; assert(1 == scanf("%lld",&k)); vector<int> ret=construct_permutation(k); if(!check_permutation(ret)) { printf("WA: Returned array is not a permutation\n"); exit(0); } long long inc=count_increasing(ret); if(inc!=k) { if(inc==MX+1) printf("WA: Expected %lld increasing subsequences, found more than %lld\n",k, MX); else printf("WA: Expected %lld increasing subsequences, found %lld\n",k,inc); exit(0); } printf("%d\n",(int)ret.size()); for(int i=0;i<ret.size();i++) { printf("%d",ret[i]); if(i+1==ret.size()) printf("\n"); else printf(" "); } } return 0; }

Compilation message (stderr)

/usr/bin/ld: /tmp/cch3xQJJ.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccKIMTV2.o:perm.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status