제출 #604465

#제출 시각아이디문제언어결과실행 시간메모리
604465pawnedArranging Shoes (IOI19_shoes)C++17
50 / 100
1083 ms3896 KiB
#include "shoes.h"

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

typedef tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

long long count_swaps(std::vector<int> s) {
	ll N = s.size() / 2;
	int shoes[2 * N];
	for (int i = 0; i < 2 * N; i++) {
		shoes[i] = s[i];
	}
	int counter = 0;
	for (int i = 0; i < 2 * N; i += 2) {
		int find = -shoes[i];
		int pos = -1;
		for (int j = i + 1; j < 2 * N; j++) {
			if (shoes[j] == find) {
				pos = j;
				break;
			}
		}
//		cout<<i<<": "<<pos<<endl;
		for (int j = pos - 1; j > i; j--) {
			swap(shoes[j], shoes[j + 1]);
			counter++;
		}
		if (shoes[i] > shoes[i + 1]) {
			swap(shoes[i], shoes[i + 1]);
			counter++;
		}
//		cout<<"counter is now "<<counter<<endl;
	}
	return counter;
}
#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...