Submission #153395

# Submission time Handle Problem Language Result Execution time Memory
153395 2019-09-14T04:08:23 Z nandonathaniel Arranging Shoes (IOI19_shoes) C++14
45 / 100
34 ms 3956 KB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> pii;

pii pas[1005];

long long count_swaps(vector<int> s) {
	if((LL)s.size()<=2000){
		vector<LL> hasil;
		LL n=(LL)s.size()/2;
		for(LL i=1;i<=n;i++)pas[i]={-1,-1};
		for(int i=0;i<s.size();i++){
			if(s[i]<0)pas[abs(s[i])].first=i;
			else pas[s[i]].second=i;
			if(pas[abs(s[i])].first!=-1 && pas[abs(s[i])].second!=-1){
				pas[abs(s[i])].first=-1;
				pas[abs(s[i])].second=-1;
			}
			else{
				hasil.push_back(-abs(s[i]));
				hasil.push_back(abs(s[i]));
			}
		}
		LL res=0;
		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++;
			}
		}
		return res;
	}
	vector<int> v;
	for(int i=0;i<s.size();i++){
		if(s[i]<0)v.push_back(i);
	}
	LL now=0,ans=0;
	for(int i=0;i<s.size();i++){
		if(i%2==0){
			ans+=abs(v[now]-i);
			now++;
		}
	}
	return ans;
}

Compilation message

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:14:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int 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:43:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<s.size();i++){
              ~^~~~~~~~~
shoes.cpp:47:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<s.size();i++){
              ~^~~~~~~~~
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 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 256 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Incorrect 2 ms 376 KB Output isn't correct
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 252 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 5 ms 632 KB Output is correct
21 Correct 5 ms 504 KB Output is correct
22 Correct 30 ms 2548 KB Output is correct
23 Correct 27 ms 2548 KB Output is correct
24 Correct 30 ms 2676 KB Output is correct
25 Correct 26 ms 2564 KB Output is correct
26 Correct 31 ms 3828 KB Output is correct
27 Correct 27 ms 3572 KB Output is correct
28 Correct 28 ms 3828 KB Output is correct
29 Correct 29 ms 3956 KB Output is correct
30 Correct 30 ms 3828 KB Output is correct
31 Correct 31 ms 3828 KB Output is correct
32 Correct 27 ms 3828 KB Output is correct
33 Correct 26 ms 3572 KB Output is correct
34 Correct 28 ms 3828 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 256 KB Output is correct
37 Correct 30 ms 3956 KB Output is correct
38 Correct 27 ms 3828 KB Output is correct
39 Correct 27 ms 3828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 34 ms 2548 KB Output is correct
6 Correct 33 ms 2596 KB Output is correct
7 Correct 33 ms 2548 KB Output is correct
8 Correct 32 ms 2548 KB Output is correct
9 Correct 33 ms 2600 KB Output is correct
10 Correct 32 ms 2548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 256 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Incorrect 2 ms 376 KB Output isn't correct
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 256 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Incorrect 2 ms 376 KB Output isn't correct
26 Halted 0 ms 0 KB -