Submission #1334472

#TimeUsernameProblemLanguageResultExecution timeMemory
1334472yhkhooArranging Shoes (IOI19_shoes)C++17
Compilation error
0 ms0 KiB
//#include "shoes.h"

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

#define pb push_back
#define eb emplace_back

ll count_swaps(std::vector<int> s) {
    int n2 = s.size();
    int n = n2/2;
    vector<pii> m;
    m.reserve(n);
    vector<vi> p(n+1);
	for(int i=0; i<n2; i++){
        if(s[i] < 0){
            m.eb(-s[i], i);
        }
        else{
            p[s[i]].pb(i);
        }
    }
    for(int i=1; i<=n; i++){
        reverse(p[i].begin(), p[i].end());
    }
    vector<int> c;
    c.reserve(n2);
    for(int i=0; i<n; i++){
        auto& [si, mi] = m[i];
        c.pb(mi);
        c.pb(p[si].back());
        p[si].pop_back();
    }
    ll ans = 0;
    for(int t=0; t<n2; t++){
        for(int i=1; i<n2; i++){
            if(c[i-1] > c[i]){
                swap(c[i-1], c[i]);
                ans++;
            }
        }
    }
    return ans;
}

int main() {
	int n;
	cin >> n;
	vector<int> S(2 * n);
	for (int i = 0; i < 2 * n; i++)
		cin >> S[i];

	long long result = count_swaps(S);
    
	cout << result;
	return 0;
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccpBIhrk.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccPGXmAX.o:shoes.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status