Submission #468637

#TimeUsernameProblemLanguageResultExecution timeMemory
468637PiejanVDCArranging Shoes (IOI19_shoes)C++17
10 / 100
1081 ms1972 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; long long count_swaps(vector<int>v) { int fixed = -1, n = v.size(); long long ans = 0; while(fixed < n-1) { int right,pos; for(int i = fixed+1 ; i < n ; i++) { if(v[i] < 0) { right = -v[i],pos=i; break; } } for(int i = pos-1 ; i > fixed ; i--) { ans++; swap(v[i],v[i+1]); } for(int i = fixed+1 ; i < n ; i++) { if(v[i] == right) { pos=i; break; } } for(int i = pos-1 ; i > fixed+1 ; i--) { ans++; swap(v[i],v[i+1]); } fixed+=2; } return ans; } /* signed main() { int n; cin>>n; vector<int>v(n); for(auto &z : v) cin >> z; cout << count_swaps(v); }*/

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:16:11: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   16 |   for(int i = pos-1 ; i > fixed ; i--) {
      |           ^
shoes.cpp:21:4: warning: 'right' may be used uninitialized in this function [-Wmaybe-uninitialized]
   21 |    if(v[i] == right) {
      |    ^~
#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...