제출 #433206

#제출 시각아이디문제언어결과실행 시간메모리
433206kostia244Arranging Shoes (IOI19_shoes)C++17
50 / 100
1083 ms1856 KiB
#include "shoes.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) begin(x), end(x)
long long count_swaps(std::vector<int> s) {
	ll res = 0;
	for(int i = 0; i < s.size(); i+=2) {
		int j = i+1;
		while(s[j] != -s[i]) j++;
		for(; j-1 > i; j--) swap(s[j], s[j-1]), res++;
		if(s[i] > 0) swap(s[i], s[i+1]), res++;

	}
	return res;

	for(auto &i : s) i *= -1;
	int n = s.size()/2;
	vector<ll> fen(2*n+1);
	auto add = [&](int x) {
		for(; x <= 2*n; x += x&-x) fen[x]++;
	};
	auto get = [&](int x) {
		int res = 0;
		add(x);
		for(; x; x -= x&-x)
			res += fen[x];
		return res;
	};
	vector<int> b(2*n);
	map<int, vector<int>> ass;
	for(int i = 0; i < 2*n; i++) ass[s[i]].push_back(i);
	for(auto &[a, b] : ass) reverse(all(b));

	vector<int> v(2*n, -69);
	for(int j = 0, i = 0; i < 2*n; i++) if(s[i] >= 0) {
		v[i] = ++j;
		v[ass[-s[i]].back()] = ++j;
		ass[-s[i]].pop_back();
	}
	for(auto &i : v) cout << i << " "; cout << endl;
	for(int i = 0; i < 2*n; i++) b[v[i]-1] = i+1;
	int cur = 0;
	for(auto i : b) {
		//cout << _ << " " << __ << " " << i << endl;
		//cout << i << " ";

		res += ++cur - get(i);
		//cout << i << " " << res << endl;
	}
	return res;
}

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:8:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |  for(int i = 0; i < s.size(); i+=2) {
      |                 ~~^~~~~~~~~~
shoes.cpp:41:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   41 |  for(auto &i : v) cout << i << " "; cout << endl;
      |  ^~~
shoes.cpp:41:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   41 |  for(auto &i : v) cout << i << " "; cout << endl;
      |                                     ^~~~
#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...