Submission #149070

# Submission time Handle Problem Language Result Execution time Memory
149070 2019-09-01T05:40:38 Z nandonathaniel Arranging Shoes (IOI19_shoes) C++14
10 / 100
3 ms 376 KB
#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;
}

Compilation message

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 time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Incorrect 1 ms 352 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Incorrect 3 ms 352 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Incorrect 1 ms 352 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Incorrect 1 ms 352 KB Output isn't correct
8 Halted 0 ms 0 KB -