Submission #137085

# Submission time Handle Problem Language Result Execution time Memory
137085 2019-07-27T04:57:23 Z baluteshih Ancient Books (IOI17_books) C++14
50 / 100
303 ms 26744 KB
#include "books.h"
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define ET cout << "\n"
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int boss[1000005],mx[1000005],mi[1000005];

int finds(int x)
{
	if(boss[x]==x) return x;
	return boss[x]=finds(boss[x]);
}

void Union(int a,int b)
{
	a=finds(a),b=finds(b);
	boss[a]=b,mx[b]=max(mx[b],mx[a]),mi[b]=min(mi[b],mi[a]);
}

long long minimum_walk(vector<int> p, int s) 
{
	ll ans=0,ls=0;
	for(int i=0;i<p.size();++i) boss[i]=i,mx[i]=i,mi[i]=i;
	for(int i=0;i<p.size();++i)
		Union(i,p[i]);
	for(int i=0;i<p.size();++i)
		ans+=abs(p[i]-i);
	for(int i=0;i<p.size();)
		if(finds(i),mx[boss[i]]==mi[boss[i]]) ++i;
		else
		{
			ans+=(mi[boss[i]]-ls)*2;
			for(ls=i;i<=mx[finds(ls)];++i)
				Union(ls,i);
			ls=i-1;
		}
	return ans;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:35:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<p.size();++i) boss[i]=i,mx[i]=i,mi[i]=i;
              ~^~~~~~~~~
books.cpp:36:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<p.size();++i)
              ~^~~~~~~~~
books.cpp:38:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<p.size();++i)
              ~^~~~~~~~~
books.cpp:40:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<p.size();)
              ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 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 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 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 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 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 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 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 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 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 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 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 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 283 ms 26668 KB Output is correct
31 Correct 303 ms 26672 KB Output is correct
32 Correct 153 ms 26744 KB Output is correct
33 Correct 167 ms 26616 KB Output is correct
34 Correct 167 ms 26616 KB Output is correct
35 Correct 173 ms 26624 KB Output is correct
36 Correct 183 ms 26744 KB Output is correct
37 Correct 207 ms 26616 KB Output is correct
38 Correct 199 ms 26744 KB Output is correct
39 Correct 196 ms 26620 KB Output is correct
40 Correct 209 ms 26548 KB Output is correct
41 Correct 260 ms 26616 KB Output is correct
42 Correct 241 ms 26744 KB Output is correct
43 Correct 177 ms 26616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 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 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 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 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 283 ms 26668 KB Output is correct
31 Correct 303 ms 26672 KB Output is correct
32 Correct 153 ms 26744 KB Output is correct
33 Correct 167 ms 26616 KB Output is correct
34 Correct 167 ms 26616 KB Output is correct
35 Correct 173 ms 26624 KB Output is correct
36 Correct 183 ms 26744 KB Output is correct
37 Correct 207 ms 26616 KB Output is correct
38 Correct 199 ms 26744 KB Output is correct
39 Correct 196 ms 26620 KB Output is correct
40 Correct 209 ms 26548 KB Output is correct
41 Correct 260 ms 26616 KB Output is correct
42 Correct 241 ms 26744 KB Output is correct
43 Correct 177 ms 26616 KB Output is correct
44 Incorrect 3 ms 376 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -