Submission #1304007

#TimeUsernameProblemLanguageResultExecution timeMemory
1304007nagorn_phArranging Shoes (IOI19_shoes)C++20
50 / 100
1096 ms1964 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()/2;
	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;
			}
			int cnt = 0;
			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;
					}
				}
				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;
					}
				}
				while (cur > i) {
					swap(a[cur], a[cur - 1]);
					cur--;
					cnt++;
				}
				ans += cnt;
			}
			// for (auto e : a) cout << e << " "; cout << " : " << cnt << "\n";
		}
		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

3 2 1 -2 -3 -1
-3 3 2 1 -2 -1: 4
-3 -3 -2 2 1 -1: 2

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