Submission #303695

#TimeUsernameProblemLanguageResultExecution timeMemory
303695rocks03Arranging Shoes (IOI19_shoes)C++14
50 / 100
1094 ms2040 KiB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int) (x).size())
using namespace std;

long long count_swaps(vector<int> s){
    int N = SZ(s);
    ll ans = 0;
    for(int i = 0; i < N;){
        int r;
        for(int j = i + 1; j < N; j++){
            if(s[i] * (-1) == s[j]){
                r = j;
                break;
            }
        }
        for(int j = r; j > i + 1; j--){
            swap(s[j], s[j-1]);
            ans++;
        }
        if(s[i] > 0){
            swap(s[i], s[i+1]);
            ans++;
        }
        i += 2;
    }
    return ans;
}

Compilation message (stderr)

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