Submission #1014340

#TimeUsernameProblemLanguageResultExecution timeMemory
1014340KasymKArranging Shoes (IOI19_shoes)C++17
10 / 100
1039 ms3164 KiB
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define ff first
#define ss second
#define all(v) v.begin(), v.end()

ll count_swaps(vector<int> v){
    int n = (int)v.size();
    ll ans = 0;
    for(int i = 0; i < n-1; i+=2){
        if(v[i] < v[i+1])
            continue;   
        else if(v[i] > v[i+1])
            swap(v[i], v[i+1]), ans++;
        else{
            int ad;
            for(int j = i+1; j < n; ++j)
                if(-v[i] == v[j]){
                    ad = j;
                    break;
                }
            for(int j = ad; j > i+1; --j)
                swap(v[j], v[j-1]), ans++;
            if(v[i] > 0)
                swap(v[i], v[i+1]), ans++;
        }
    }
    return ans;
}

// int main(){
//     ll answer = count_swaps({-2, 2, 2, -2, -2, 2});
//     printf("%lld\n", answer);
// }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:24:25: warning: 'ad' may be used uninitialized in this function [-Wmaybe-uninitialized]
   24 |                 swap(v[j], v[j-1]), ans++;
      |                         ^
#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...