Submission #575577

#TimeUsernameProblemLanguageResultExecution timeMemory
575577lucriPermutation (APIO22_perm)C++17
100 / 100
2 ms352 KiB
#include "perm.h" #include <cstdio> #include <vector> #include <cassert> #include <algorithm> #include <stdlib.h> /* using namespace std; 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; } */ void ans(long long n,std::vector<int> &a) { if(n<=15) { if(n==2) a.push_back(0); if(n==3) { a.push_back(1); a.push_back(0); } if(n==4) { a.push_back(2); a.push_back(1); a.push_back(0); } if(n==5) { a.push_back(3); a.push_back(2); a.push_back(1); a.push_back(0); } if(n==6) { a.push_back(4); a.push_back(3); a.push_back(2); a.push_back(1); a.push_back(0); } if(n==7) { a.push_back(5); a.push_back(4); a.push_back(3); a.push_back(2); a.push_back(1); a.push_back(0); } if(n==8) { a.push_back(4); a.push_back(3); a.push_back(1); a.push_back(0); a.push_back(2); } if(n==9) { a.push_back(5); a.push_back(4); a.push_back(3); a.push_back(1); a.push_back(0); a.push_back(2); } if(n==10) { a.push_back(1); a.push_back(2); a.push_back(0); a.push_back(3); } if(n==11) { a.push_back(4); a.push_back(1); a.push_back(2); a.push_back(0); a.push_back(3); } if(n==12) { a.push_back(5); a.push_back(4); a.push_back(1); a.push_back(2); a.push_back(0); a.push_back(3); } if(n==13) { a.push_back(4); a.push_back(1); a.push_back(0); a.push_back(2); a.push_back(3); } if(n==14) { a.push_back(5); a.push_back(4); a.push_back(1); a.push_back(0); a.push_back(2); a.push_back(3); } if(n==15) { a.push_back(1); a.push_back(0); a.push_back(4); a.push_back(2); a.push_back(3); } return; } ans(n/4,a); if(n%4==0) { a.push_back(a.size()); a.push_back(a.size()); } if(n%4==1) { a.push_back(a.size()); a.push_back(a.size()); for(int i=0;i<=a.size();++i) ++a[i]; a.push_back(0); } if(n%4==2) { a.push_back(a.size()); for(int i=0;i<=a.size();++i) ++a[i]; a.push_back(0); a.push_back(a.size()); } if(n%4==3) { a.push_back(a.size()); a.push_back(a.size()); for(int i=0;i<=a.size();++i) if(a[i]>=2) ++a[i]; a.push_back(2); } return; } std::vector<int> construct_permutation(long long k) { std::vector<int> a; ans(k,a); return a; } /* int main() { int t; assert(1 == scanf("%d", &t)); long long k=1; while(t--) { 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)

perm.cpp: In function 'void ans(long long int, std::vector<int>&)':
perm.cpp:158:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  158 |         for(int i=0;i<=a.size();++i)
      |                     ~^~~~~~~~~~
perm.cpp:165:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  165 |         for(int i=0;i<=a.size();++i)
      |                     ~^~~~~~~~~~
perm.cpp:174:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  174 |         for(int i=0;i<=a.size();++i)
      |                     ~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...