Submission #335425

#TimeUsernameProblemLanguageResultExecution timeMemory
335425MohammadHijazArranging Shoes (IOI19_shoes)C++14
10 / 100
1089 ms3184 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std; long long count_swaps(std::vector<int> s) { int x = s.size(); int last = 0; long long ans = 0; for (int i = 0; i < x; i++) { if (s[i]*-1 > 0) { int j = i; while(s[last] != s[j]) { swap(s[j] , s[j - 1]); j--; ans++; } int tar; for (int j = last + 1; j < x; j++) { if (s[j] == s[last]*-1) { tar = j; break; } } while(s[last]*-1 != s[last+1]) { swap(s[tar] , s[tar - 1]); tar--; ans++; } last += 2; } } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:16:17: warning: 'tar' may be used uninitialized in this function [-Wmaybe-uninitialized]
   16 |             int tar;
      |                 ^~~
#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...