제출 #297329

#제출 시각아이디문제언어결과실행 시간메모리
297329amoo_safarArranging Shoes (IOI19_shoes)C++17
0 / 100
7 ms9728 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> I[N];
int v[N];

ll count_swaps(vector<int> s) {
	int n = s.size() >> 1;
	for(int i = 0; i < n + n; i++){
		V[abs(s[i])].pb(s[i] < 0 ? -1 : +1);
		I[abs(s[i])].pb(i);
	}
	int sm = 0;
	ll res = 0;
	for(int i = 1; i <= n; i++){
		sm = 0;
		for(int j = 0; j < (int) V[i].size(); j++){
			if(V[i][j] == 1) sm ++;
			res += abs(sm - ((j + 1) / 2));
		}
		for(int j = 0; j + 1 < (int) I[i].size(); j += 2)
			v[V[i][j]] = v[V[i][j + 1]] = V[i][j];
	}
	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...