Submission #807717

#TimeUsernameProblemLanguageResultExecution timeMemory
807717Essa2006Arranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
//#include "shoes.h"
#include <cstdio>
#include <cassert>
using namespace std;
#define ll long long 
#define endl '\n'
#define FF firtst
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)
ll count_swaps(vector<int> S){
    bool same=1;
    int n=2*S.size();
    for(int i=1;i<n;i++){
        if(abs(S[i])!=abs(S[i-1]))
            same=0;
    }
    if(n/2<=1000){
        int ans=0;
        for(int i=0;i<n;i++){
            if(S[i]>0){
                bool found=0;
                int ind=0;
                for(int j=0;j<i;j++){
                    if(-S[j]==S[i] && S[j+1]!=-S[i]){
                        found=1;
                        ind=j;
                        break;
                    }
                }
                if(found){
                    for(int j=i-1;j>ind;j--){
                        swap(S[j], S[j+1]);
                        ans++;
                    }
                }
            }
            else if(S[i]<0){
                bool found=0;
                int ind=0;
                for(int j=0;j<i;j++){
                    if(-S[j]==S[i] && (!j || S[j]!=-S[j-1])){
                        found=1;
                        ind=j;
                        break;
                    }
                }
                if(found){
                    for(int j=i-1;j>=ind;j--){
                        swap(S[j], S[j+1]);
                        ans++;
                    }
                }
            }
        }
        return ans;
    }
    if(n/2>1000 && !same){
        ll ans=S.size()/2;
        return ans*(ans-1)/2;
    }
}


int main() {
	int n;
	assert(1 == scanf("%d", &n));
	vector<int> S(2 * n);
	for (int i = 0; i < 2 * n; i++)
		assert(1 == scanf("%d", &S[i]));
	fclose(stdin);

	long long result = count_swaps(S);

	printf("%lld\n", result);
	fclose(stdout);
	return 0;
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:63:1: warning: control reaches end of non-void function [-Wreturn-type]
   63 | }
      | ^
/usr/bin/ld: /tmp/ccNkKfLG.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccKGtKyI.o:shoes.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status