제출 #760247

#제출 시각아이디문제언어결과실행 시간메모리
760247raysh07Arranging Shoes (IOI19_shoes)C++17
10 / 100
1089 ms8896 KiB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;

long long count_swaps(std::vector<int> s) {
	long long ans = 0;
	int n = s.size() / 2;
	vector<pair<int, int>> a;
	vector<int> adj[n + 1];
	
	for (int i = 0; i < 2 * n; i++){
	    if (s[i] < 0) {
	        a.push_back({-s[i], i});
	    } else {
	        adj[s[i]].push_back(i);
	    }
	}
	
	for (int i = 1; i <= n; i++) reverse(adj[i].begin(), adj[i].end());
	
	vector <int> realpos(2 * n, -1);
	
	int pos = 0;
	
	for (auto [x, y] : a){
	    realpos[y] = pos;
	    realpos[adj[x].back()] = pos + 1;
	    adj[x].pop_back();
	    pos += 2;
	}
	
// 	for (int i = 0; i < 2 * n; i++) cout << realpos[i] << " ";
// 	cout << "\n";
	for (int i = 0; i < 2 * n; i++){
	    for (int j = i + 1; j < 2 * n; j++){
	        if (realpos[j] < realpos[i]) ans++;
	    }
	}
	
	return ans;
}

// int main(){
//     int n; cin >> n;
//     vector <int> a(n);
//     for (auto &x : a) cin >> x;
    
//     cout << count_swaps(a) << "\n";
//   return 0; 
// }
#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...