Submission #602964

#TimeUsernameProblemLanguageResultExecution timeMemory
602964definitelynotmeeArranging Shoes (IOI19_shoes)C++17
50 / 100
1083 ms3128 KiB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using matrix = vector<vector<T>>;
#define ff first
#define ss second
#define all(x) x.begin(), x.end()

long long count_swaps(std::vector<int> v) {
    
    int n = v.size();
    ll resp = 0;
    auto solve =[&](int id, auto solve)->void{
        if(id >= n)
            return;
        int par;
        for(int i = id+ 1; i < n; i++){
            if(v[i] == v[id]*-1){
                par = i;
                break;
            }
        }
        for(int i = par-1; i > id; i--){
            swap(v[i],v[i+1]);
            // for(int i : v){
            //     cout << i << ' ';
            // }
            // cout << '\n';
            resp++;
        }
        if(v[id] > v[id+1]){
            swap(v[id],v[id+1]), resp++;
            // for(int i : v){
            //     cout << i << ' ';
            // }
            // cout << '\n';
        }
        solve(id+2,solve);
    };
    solve(0,solve);

    

    return resp;
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:26:17: warning: 'par' may be used uninitialized in this function [-Wmaybe-uninitialized]
   26 |         for(int i = par-1; i > id; i--){
      |                 ^
#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...