Submission #199003

#TimeUsernameProblemLanguageResultExecution timeMemory
199003TadijaSebezSwap (BOI16_swap)C++11
0 / 100
6 ms504 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair const int inf=1e9+7; pair<int,int> min(pair<int,int> a,pair<int,int> b){return a<b?a:b;} vector<int> mrg(vector<int> a,vector<int> b){ while(b.size())a.pb(b.back()),b.pop_back(); return a; } int main(){ int n; scanf("%i",&n); vector<vector<int>> a(n*2+5,vector<int>(0)); vector<bool> was(n+1,0); for(int i=1,j;i<=n;i++)scanf("%i",&j),a[i].pb(j); for(int i=n+1;i<a.size();i++)a[i].pb(inf); for(int i=1;i<=n;i++){ sort(a[i].rbegin(),a[i].rend()); while(was[a[i].back()])a[i].pop_back(),assert(a[i].size()); int ch=i<<1|1; if(a[i<<1][0]<a[i<<1|1][0])ch=i<<1; if(a[ch][0]<a[i].back()){ if(ch&1){ vector<int> tmp=mrg(a[i],a[ch^1]); a[i]=a[ch]; a[ch]=a[ch^1]=tmp; }else{ swap(a[i],a[ch]); } }else{ int my=a[i].back(); a[i].clear(); a[i].pb(my); } was[a[i][0]]=1; printf("%i ",a[i][0]); } return 0; }

Compilation message (stderr)

swap.cpp: In function 'int main()':
swap.cpp:17:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=n+1;i<a.size();i++)a[i].pb(inf);
                ~^~~~~~~~~
swap.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i",&n);
  ~~~~~^~~~~~~~~
swap.cpp:16:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1,j;i<=n;i++)scanf("%i",&j),a[i].pb(j);
                         ~~~~~~~~~~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...