Submission #195648

#TimeUsernameProblemLanguageResultExecution timeMemory
195648SwanArranging Shoes (IOI19_shoes)C++14
50 / 100
1097 ms3192 KiB
#include <bits/stdc++.h>
#include "shoes.h"
#define stop system("pause")
#define stop2 char o; cin >> o
#define INP freopen("pcb.in","r",stdin)
#define OUTP freopen ("pcb.out","w",stdout)
using namespace std;

long long count_swaps(std::vector<int> s) {
    int ans = 0;
    for(int i(0); i < s.size();i+=2){
        if(s[i] == -s[i+1] && s[i] < 0 && s[i+1] > 0)continue;
        int need;
        for(int to(i+1); to < s.size();to++){
            if(s[to]!=-s[i])continue;
            else{
                need = to;
                break;
            }
        }
        while(need!=i){
            swap(s[need],s[need-1]);
            need--;
            ans++;
        }
        if(s[i] > 0){
            ans--;
            swap(s[i],s[i+1]);
        }
        //cout << i+1 << ' ' << ans << endl;
    }
	return ans;
}

/*
6
-2 2 2 -2 -2 2
*/
/*
main(){
    ios_base::sync_with_stdio(0);
    int n; cin >> n;
    vector<int> v;
    for(int i(0); i < n;i++){
        int x; cin >> x;
        v.push_back(x);
    }
    cout << count_swaps(v);
    return 0;
}*/
/*
*/

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:11:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i(0); i < s.size();i+=2){
                   ~~^~~~~~~~~~
shoes.cpp:14:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int to(i+1); to < s.size();to++){
                          ~~~^~~~~~~~~~
shoes.cpp:13:13: warning: 'need' may be used uninitialized in this function [-Wmaybe-uninitialized]
         int need;
             ^~~~
#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...