제출 #149070

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

LL a[100],V[100];

long long count_swaps(vector<int> s) {
	LL n=(LL)s.size(),now=0;
	n/=2;
	for(LL i=0;i<s.size();i++){
		if(s[i]>0){
			now++;
			a[now]=s[i];
			V[now]=now;
		}
	}
	LL ans=1e18;
	do{
		LL res=0;
		vector<LL> hasil;
		for(LL i=1;i<=n;i++){
			hasil.push_back(-a[V[i]]);
			hasil.push_back(a[V[i]]);
		}
		//for(LL i=1;i<=2*n;i++)cout << hasil[i-1] << endl;
		for(LL i=0;i<s.size();i++){
			LL no;
			for(LL j=i;j<s.size();j++){
				if(s[j]==hasil[i]){
					no=j;
					break;
				}
			}
			for(LL j=no;j>=i+1;j--){
				swap(s[j],s[j-1]);
				res++;
			}
		}
		ans=min(ans,res);
	}while(next_permutation(V+1,V+n+1));
	return ans;
}

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:11:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(LL i=0;i<s.size();i++){
             ~^~~~~~~~~
shoes.cpp:27:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(LL i=0;i<s.size();i++){
              ~^~~~~~~~~
shoes.cpp:29:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(LL j=i;j<s.size();j++){
               ~^~~~~~~~~
shoes.cpp:28:7: warning: 'no' may be used uninitialized in this function [-Wmaybe-uninitialized]
    LL no;
       ^~
#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...