Submission #297351

#TimeUsernameProblemLanguageResultExecution timeMemory
297351amoo_safarArranging Shoes (IOI19_shoes)C++17
50 / 100
1058 ms23032 KiB
#include "shoes.h"

#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end();

using namespace std;

typedef long long ll;

const int N = 2e5 + 10;
vector<int> V[N];
vector<int> pos[N], neg[N];
int v[N];

ll count_swaps(vector<int> s) {
	int n = s.size() >> 1;
	for(int i = 0; i < n + n; i++){
		if(s[i] > 0)
			pos[abs(s[i])].pb(i);
		else
			neg[abs(s[i])].pb(i);
	}
	ll res = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < (int) pos[i].size(); j++){
			v[pos[i][j]] = v[neg[i][j]] = min(pos[i][j], neg[i][j]);
			if(v[pos[i][j]] == pos[i][j])
				res ++;
		}
	}
	for(int i = 1; i < n + n; i++)
		for(int j = 0; j < i; j++)
			res += (v[j] > v[i]);
	return res;
}
#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...