Submission #1304006

#TimeUsernameProblemLanguageResultExecution timeMemory
1304006nagorn_phArranging Shoes (IOI19_shoes)C++20
10 / 100
1095 ms1960 KiB
#include "shoes.h"
#include <bits/stdc++.h>
#define ll long long
#define emb emplace_back
#define em emplace
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pii pair <int, int>

using namespace std;

ll count_swaps(vector<int> a) {
	int n = a.size();
	ll ans = 0;
	for (int i = 0; i < 2*n; i++) {
		if (i % 2 == 0) {
			if (a[i] < 0 && a[i + 1] == -1 * a[i]) {
				continue;
			}
			if (a[i] < 0) {
				int cur = 0;
				for (int j = i + 1; j < 2*n; j++) {
					if (a[j] == -1 * a[i]) {
						cur = j;
						break;
					}
				}
				int cnt = 0;
				while (cur > i + 1) {
					swap(a[cur], a[cur - 1]);
					cur--;
					cnt++;
				}
				ans += cnt;
			}
			else {
				int cur = 0;
				for (int j = i + 1; j < 2*n; j++) {
					if (a[j] == -1 * a[i]) {
						cur = j;
						break;
					}
				}
				int cnt = 0;
				while (cur > i) {
					swap(a[cur], a[cur - 1]);
					cur--;
					cnt++;
				}
				ans += cnt;
			}
		}
		else {
			if (a[i] > 0 && a[i - 1] == -1 * a[i]) {
				continue;
			}
		}
	}
	return ans;
}

/*
sub3: find closest position
sub4: 
-1 1 : 0
-1 -2 1 2 : 1
-1 -2 -3 1 2 3 : 3
ans = n(n-1)/2
sub5: n^2
for each idx i: find closest left/right shoe then 
just count number of swaps, then change index of 
other shoes accordingly..?
_,_,_,X,_,_,Y,_,X,_,_,Y

*/
#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...