제출 #143321

#제출 시각아이디문제언어결과실행 시간메모리
143321VladaMG98Arranging Shoes (IOI19_shoes)C++17
50 / 100
1081 ms1960 KiB
#include <bits/stdc++.h>
using namespace std;
#include "shoes.h"
long long count_swaps(std::vector<int> s) {
	int n = (int)s.size() / 2;
	int N = 2 * n;
	long long ans = 0;
	for(int pos = 0; pos < n; pos++) {
        //printf("pos = %d\n", pos);
        int target = -s[2 * pos];
        int fnd = -1;
		for(int i = 2 * pos + 1; i < N; i++) {
			if(s[i] == target) {
				fnd = i;
				break;
			}
		}
		assert(fnd + 1);
		for(int i = fnd - 1; i >= 2 * pos + 1; i--) {
			swap(s[i], s[i + 1]);
			ans += 1;
		}
		if(s[2 * pos] > 0) {
            swap(s[2 * pos], s[2 * pos + 1]);
            ans += 1;
		}
        //printf("ans = %d\n", ans);
	}
	return 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...