Submission #152483

#TimeUsernameProblemLanguageResultExecution timeMemory
152483WLZArranging Shoes (IOI19_shoes)C++17
10 / 100
1083 ms1936 KiB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;

long long count_swaps(vector<int> s) {
  long long ans = 0;
  int n = (int) s.size() / 2;
  for (int i = 0; i < n; i++) {
    int pos = i * 2;
    if (s[pos] > 0) {
      int other;
      for (int j = pos + 1; j < 2 * n; j++) {
        if (s[j] < 0) {
          other = j;
          break;
        }
      }
      for (int j = other; j > pos; j--) {
        swap(s[j], s[j - 1]);
        ans++;
      }
    }
    if (s[pos + 1] != -s[pos]) {
      int other;
      for (int j = pos + 2; j < 2 * n; j++) {
        if (s[j] == -s[pos]) {
          other = j;
          break;
        }
      }
      for (int j = other; j > pos + 1; j--) {
        swap(s[j], s[j - 1]);
        ans++;
      }
    }
  }
	return ans;
}

Compilation message (stderr)

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