제출 #1030152

#제출 시각아이디문제언어결과실행 시간메모리
1030152enderArranging Shoes (IOI19_shoes)C++17
45 / 100
36 ms4564 KiB
#include "shoes.h"
#include <bits/stdc++.h>

using namespace std;

long long count_swaps(std::vector<int> s) {

	long long ans = 0;
	int cl = 0, cr = 0;
	priority_queue<int, vector<int>, greater<int>> l, r;

	for(int i = 0; i < s.size(); ++i){

		if(s[i] < 0) l.push(i);
		else r.push(i);

	}

	for(int i = 0; i < s.size(); ++i){

		if(i%2 == 0){

			if(s[i] > 0){
				
				ans += l.top() - i;
				swap(s[i], s[l.top()]);
				r.pop();
				r.push(l.top());
			} 

			l.pop();

		}else {

			if(s[i] < 0){

				ans += r.top() - i;
				swap(s[i], s[r.top()]);	
				l.pop();
				l.push(r.top());
			} 
			
			r.pop();

		}

	}

	return ans;
}

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:12:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |  for(int i = 0; i < s.size(); ++i){
      |                 ~~^~~~~~~~~~
shoes.cpp:19:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |  for(int i = 0; i < s.size(); ++i){
      |                 ~~^~~~~~~~~~
shoes.cpp:9:6: warning: unused variable 'cl' [-Wunused-variable]
    9 |  int cl = 0, cr = 0;
      |      ^~
shoes.cpp:9:14: warning: unused variable 'cr' [-Wunused-variable]
    9 |  int cl = 0, cr = 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...