Submission #959326

#TimeUsernameProblemLanguageResultExecution timeMemory
959326zeta7532Permutation (APIO22_perm)C++17
Compilation error
0 ms0 KiB
//#include "perm.h" #include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; using ll = long long; const ll mod = 998244353; #define fi first #define se second #define rep(i,n) for(ll i=0;i<n;i++) #define all(x) x.begin(),x.end() #define faster ios::sync_with_stdio(false);cin.tie(nullptr) std::vector<int> construct_permutation(long long k) { if(k==2) return {0}; if(k%2==0){ vector<int> A=construct_permutation(k/2); A.push_back(A.size()); return A; } if(k%2==1){ vector<int> A=construct_permutation(k-1); rep(i,A.size()) A[i]++; A.push_back(0); return A; } } 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)

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:11:30: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 | #define rep(i,n) for(ll i=0;i<n;i++)
......
   25 |      rep(i,A.size()) A[i]++;
      |          ~~~~~~~~~~           
perm.cpp:25:6: note: in expansion of macro 'rep'
   25 |      rep(i,A.size()) A[i]++;
      |      ^~~
perm.cpp: In function 'bool check_permutation(std::vector<int>)':
perm.cpp:36:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |  for(int i=0;i<v.size();i++)
      |              ~^~~~~~~~~
perm.cpp: In function 'int main()':
perm.cpp:83:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |   for(int i=0;i<ret.size();i++)
      |               ~^~~~~~~~~~~
perm.cpp:86:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |    if(i+1==ret.size())
      |       ~~~^~~~~~~~~~~~
perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:29:1: warning: control reaches end of non-void function [-Wreturn-type]
   29 | }
      | ^
/usr/bin/ld: /tmp/ccCGJdSd.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccUVW3gf.o:perm.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status