제출 #423609

#제출 시각아이디문제언어결과실행 시간메모리
423609MazaalaiArranging Shoes (IOI19_shoes)C++14
10 / 100
1 ms204 KiB
#include "shoes.h"
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

long long count_swaps(vector<int> s) {
	ll ans = 0, n = s.size();
	map <int, vector <int> > l, r;
	for (int i = 0; i < n; i++) {
		if (s[i] < 0) 
			l[-s[i]].push_back(i);
		else
			r[s[i]].push_back(i);
	}
	vector <pair <int, int> > lines;
	vector <int> lineCnt(n+5, 0);
	for (auto el : l) {
		int val = el.first;
		vector <int> a = el.second, b = r[val];
		for (int i = 0; i < a.size(); i++) {
			int x = a[i], y = b[i];
			// cout << x << ' ' << y << '\n';
			if (x < y && x + 1 <= y) {
				ans += y - (x+1);
				lines.push_back({x+1, y-1});
				lineCnt[x+1]++;
				lineCnt[y]--;
			}
			if (x > y && y <= x-1) {
				swap(x, y);
				ans += y - x;
				lines.push_back({x, y-1});
				lineCnt[x]++;
				lineCnt[y]--;
			}
		}
	}
	for (int i = 1; i < n+5; i++) lineCnt[i] += lineCnt[i-1];
	// for (int i = 0; i < n; i++) cout << lineCnt[i] << ' ';
	// cout << '\n';
	for (auto [a, b] : lines) {
		// cout << a << ' ' << b << '\n';
		if (lineCnt[a] < lineCnt[b]) {
			ans -= lineCnt[b] - lineCnt[a];
		}
	}

	// sort(lines.begin(), lines.end());
	// for 
	return ans;
}

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:20:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |   for (int i = 0; i < a.size(); i++) {
      |                   ~~^~~~~~~~~~
shoes.cpp:41:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   41 |  for (auto [a, b] : lines) {
      |            ^
#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...