Submission #645646

#TimeUsernameProblemLanguageResultExecution timeMemory
645646czhang2718Permutation (APIO22_perm)C++17
Compilation error
0 ms0 KiB
#include "bits/stdc++.h" using namespace std; // #include "perm.h" std::vector<int> construct_permutation(long long S) { vector<int> v; bool emp=1; for(int i=30; i>=0; i--){ int d=(S/(1LL<<(2*i)))%4; if(emp){ if(!d) continue; if(d==1) {} if(d==2) v={0}; if(d==3) v={1,0}; emp=0; continue; } if(d==0){ int mx=(v.size()?*max_element(v.begin(), v.end()):0); v.push_back(mx+1); v.push_back(mx+2); } if(d==1){ int mx=(v.size()?*max_element(v.begin(), v.end()):0); v.push_back(mx+1); v.push_back(mx+2); int mn=(v.size()?*min_element(v.begin(), v.end()):0); v.push_back(mn-1); } if(d==2){ int mx=(v.size()?*max_element(v.begin(), v.end()):0); v.push_back(mx+1); int mn=(v.size()?*min_element(v.begin(), v.end()):0); v.push_back(mn-1); v.push_back(mx+2); } if(d==3){ if(!v.size()) v={2, 1, 0}; else{ int mx=(v.size()?*max_element(v.begin(), v.end()):0); v.push_back(mx+1); v.push_back(mx+2); int mn=(v.size()?*min_element(v.begin(), v.end()):0); int i0,i1; for(int j=0; j<v.size(); j++){ if(v[j]==mn) i0=j; if(v[j]==mn+1) i1=j; } if(i1<i0){ v[i0]--, v[i1]--; v.push_back(mn+1); } else{ v.push_back(mn-2); v.push_back(mn-1); } } } } vector<int> a=v; sort(a.begin(), a.end()); for(int &x:v) x=lower_bound(a.begin(), a.end(), x)-a.begin(); return v; } int main(){ cin.tie(0)->sync_with_stdio(0); int k; cin >> k; for(int x:construct_permutation(k)) cout << x << " "; }

Compilation message (stderr)

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:47:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |                 for(int j=0; j<v.size(); j++){
      |                              ~^~~~~~~~~
perm.cpp:52:34: warning: 'i1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   52 |                     v[i0]--, v[i1]--;
      |                                  ^
perm.cpp:52:25: warning: 'i0' may be used uninitialized in this function [-Wmaybe-uninitialized]
   52 |                     v[i0]--, v[i1]--;
      |                         ^
/usr/bin/ld: /tmp/ccsRX6vx.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc7LjCJw.o:perm.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status