제출 #428218

#제출 시각아이디문제언어결과실행 시간메모리
428218HazemArranging Shoes (IOI19_shoes)C++14
50 / 100
1096 ms3552 KiB
#include "shoes.h"
#include <bits/stdc++.h>

#define LL long long
#define F first
#define S second

using namespace std;

const int N = 2e5+10;

vector<pair<LL,LL>>vec;
bool matched[N];

long long count_swaps(std::vector<int> s) {
	
	LL n = s.size()/2,ans = 0;
	int cnt = 0;

	for(int i=0;i<n*2;i++){
		if(s[i]<0){
			bool q = 0;
			for(int j=0;j<i;j++)
				if(s[j]==abs(s[i])&&!matched[j]){
					vec.push_back({i,j});ans += abs(i-j);
					q = 1;
					matched[j] = 1;
					break;
				}
			if(q)continue;
			for(int j=i+1;j<n*2;j++)
				if(s[j]==abs(s[i])&&!matched[j]){
					vec.push_back({i,j});ans += abs(i-j)-1;
					matched[j] = 1;
					break;
				}
		}
	}

	for(int i=0;i<vec.size();i++){
		for(int j=i+1;j<vec.size();j++){
			
			pair<int,int>p1 = make_pair(min(vec[i].F,vec[i].S),max(vec[i].F,vec[i].S));
			pair<int,int>p2 = make_pair(min(vec[j].F,vec[j].S),max(vec[j].F,vec[j].S));

			pair<int,int>p3 = make_pair(max(p1.F,p2.F),min(p1.S,p2.S));
			if(p3!=p1&&p3!=p2&&p3.F<p3.S)
				ans--;
		}
	}
	return ans;
}

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:40:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |  for(int i=0;i<vec.size();i++){
      |              ~^~~~~~~~~~~
shoes.cpp:41:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   for(int j=i+1;j<vec.size();j++){
      |                 ~^~~~~~~~~~~
shoes.cpp:18:6: warning: unused variable 'cnt' [-Wunused-variable]
   18 |  int cnt = 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...