Submission #808665

#TimeUsernameProblemLanguageResultExecution timeMemory
808665KemalKArranging Shoes (IOI19_shoes)C++17
10 / 100
1095 ms145800 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; typedef long long int ll; int n; long long count_swaps(std::vector<int> s) { n = s.size(); if (n == 2){ if (s[0] < 0){ return 0; } return 1; } map <int, deque<int>> pos_right; map <int, deque<int>> pos_left; for (int i = 0; i < n; i++){ if (s[i] > 0){ pos_right[s[i]].push_back(i); } else{ pos_left[s[i]].push_back(i); } } ll ans = 0; vector <bool> used (n + 1, false); for (int i = 0; i < n; i++){ if (!used[i]){ // cout << i << "\n"; // left; if (s[i] < 0){ // cout << "left" << "\n"; int nxt; for (int j = i + 1; j < n; j++){ if (!used[j] and abs(s[i]) == s[j]){ ans += (j - i - 1ll); nxt = j; break; } } for (int j = nxt; j > i + 1; j--){ swap(s[j], s[j - 1]); } used[i] = true; used[i + 1] = true; } else{ // right // cout << "right" << "\n"; int nxt; for (int j = i + 1; j < n; j++){ if (!used[j] and s[i] == abs(s[j])){ nxt = j; ans += (j - i); break; } } for (int j = nxt; j > i; j--){ swap(s[j], s[j - 1]); } used[i] = true; used[i + 1] = true; } } } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:57:14: warning: 'nxt' may be used uninitialized in this function [-Wmaybe-uninitialized]
   57 |      swap(s[j], s[j - 1]);
      |              ^
shoes.cpp:32:9: warning: 'nxt' may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |     int nxt;
      |         ^~~
#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...