제출 #559364

#제출 시각아이디문제언어결과실행 시간메모리
559364LastRoninArranging Shoes (IOI19_shoes)C++14
50 / 100
1076 ms10788 KiB
//#include "shoes.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
 
const ll N = 2e5;
 
ll n;
vector<ll> st, ex[N];
 
long long count_swaps(vector<int> s) {
	n = s.size();
	ll pos = 0;
	for(auto u : s) {
		if(u < 0) {
			st.pb(pos++);
		}
		else {
			ex[u].pb(pos++);
		}
	}
	for(int j = 1; j <= n; j++) {
		reverse(ex[j].begin(), ex[j].end());
	}
	ll ans = 0;
	for(int j = 0; j < n; j += 2) {
		ll z = -1;
		if(s[j] < 0) {
			for(int i = j + 1; i < n; i++) {
				if(s[i] == -s[j]) {
					z = i;
					break;
				}
			}
			for(int i = z; i > j + 1; i--)
				swap(s[i], s[i - 1]), ans++;
		}
		else {
			for(int i = j + 1; i < n; i++) {
				if(s[i] == -s[j]) {
					z = i;
					break;
				}
			}
			for(int i = z; i > j; i--)
				swap(s[i], s[i - 1]), ans++;
		}
	}
	return ans;
}
/*
int main() {
	int n;
	vector<int> s;
	cin >> n;
	for(int i = 0; i < n; i++) {
		s.pb(0);
		cin >> s.back();
	}
	cout << count_swaps(s);	
}
/**/

컴파일 시 표준 에러 (stderr) 메시지

shoes.cpp:63:1: warning: "/*" within comment [-Wcomment]
   63 | /**/
      |
#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...