Submission #236805

#TimeUsernameProblemLanguageResultExecution timeMemory
236805michaoArranging Shoes (IOI19_shoes)C++14
50 / 100
1093 ms3200 KiB
#include <bits/stdc++.h> #define ll long long int #define mp make_pair #define pb push_back #define ld long double #define pii pair<int,int> #define sz(x) (int)x.size() #define piii pair<pii,pii> #define precise cout<<fixed<<setprecision(10) #define st first #define nd second #define ins insert #define vi vector<int> #define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) using namespace std; const int MAX=1e5+5; int pos[MAX*2]; ll count_swaps(vi tab) { int ans=0; int n=sz(tab); int ile=sz(tab)/2; for (int i=0;i<n-1;i+=2) { int wsk=0; wsk=-tab[i]; int akt=-1e6+5; for (int j=i+1;j<n;j++) { if (tab[j]==wsk) { akt=j; break; } } // cout<<"TERAZ "<<akt<<" "<<wsk<<"\n"; if (akt>i) { for (int j=akt;j>=i+2;j--)swap(tab[j],tab[j-1]),ans++; if (tab[i]>tab[i+1])swap(tab[i],tab[i+1]),ans++; } else if (tab[i]>tab[i+1])swap(tab[i],tab[i+1]),ans++; //cout<<"ZAWARTOSC "<<n<<"\n"; //for (auto it:tab)cout<<it<<" "; //cout<<"\n"; } return ans; } /* int main() { cout<<count_swaps({-2, 2, 2, -2, -2, 2}); } */

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:22:6: warning: unused variable 'ile' [-Wunused-variable]
  int ile=sz(tab)/2;
      ^~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...