Submission #581927

# Submission time Handle Problem Language Result Execution time Memory
581927 2022-06-23T08:13:28 Z Koosha_mv Ancient Books (IOI17_books) C++14
100 / 100
563 ms 180360 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
 
const int N=2e6+99;
const ll inf=1e15;
 
int n,vis[N],mx1[N],mx2[N],mn1[N],mn2[N];
ll Max[N],dist[N];
queue<int> Q;
vector<int> vec,prt[N];
vector<pair<int,int>> g[N];
 
ll minimum_walk(vector<int> p, int s){
	ll sum=0,ans=0;
	n=p.size();
	int l=n,r=0;
	f(i,0,n){
		sum+=abs(p[i]-i);
		if(p[i]!=i) minm(l,i),maxm(r,i);
	}
	minm(l,s);
	maxm(r,s);
	if(l==r) return 0;
	s-=l;
	f(i,l,r+1) vec.pb(p[i]-l);
	p=vec;
	n=p.size();
	int mx=0;
	l=0,r=n-1;
	f(i,0,s){
		maxm(mx,p[i]);
		if(mx==i){
			ans+=2;
			l=i+1;
		}
	}
	int mn=n;
	f_(i,n-1,s+1){
		minm(mn,p[i]);
		if(mn==i){
			ans+=2;
			r=i-1;
		}
	}
	if(l==r) return sum+ans;
	vec.clear(); s-=l;
	f(i,l,r+1) vec.pb(p[i]-l);
	p=vec;
	n=p.size();
	f(i,0,n){
		g[i].pb({p[i],0});
	}
	f_(i,s,1){
		g[i].pb({i-1,1});
		g[i-1].pb({i,0});
	}
	f(i,s,n-1){
		g[i].pb({i+1,1});
		g[i+1].pb({i,0});
	}
	//eror(n);
	prt[0].pb(s);
	f(i,0,n) dist[i]=(i==s ? 0 : N);
	f(i,0,n){
		f(j,0,prt[i].size()){
			int u=prt[i][j];
			for(auto [v,w] : g[u]){
				if(dist[u]+w<dist[v]){
					dist[v]=dist[u]+w;
					prt[dist[v]].pb(v);
				}
			}
		}
	}
	//eror(dist[0]);
	return ans+sum+2ll*dist[0];
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:9:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 | #define f(i,a,b) for(int i=a;i<b;i++)
......
   85 |   f(j,0,prt[i].size()){
      |     ~~~~~~~~~~~~~~~~~          
books.cpp:85:3: note: in expansion of macro 'f'
   85 |   f(j,0,prt[i].size()){
      |   ^
books.cpp:87:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   87 |    for(auto [v,w] : g[u]){
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 44 ms 94224 KB Output is correct
2 Correct 47 ms 94224 KB Output is correct
3 Correct 54 ms 94184 KB Output is correct
4 Correct 46 ms 94228 KB Output is correct
5 Correct 44 ms 94124 KB Output is correct
6 Correct 46 ms 94208 KB Output is correct
7 Correct 43 ms 94128 KB Output is correct
8 Correct 55 ms 94232 KB Output is correct
9 Correct 51 ms 94224 KB Output is correct
10 Correct 45 ms 94220 KB Output is correct
11 Correct 60 ms 94224 KB Output is correct
12 Correct 46 ms 94228 KB Output is correct
13 Correct 45 ms 94212 KB Output is correct
14 Correct 46 ms 94220 KB Output is correct
15 Correct 45 ms 94156 KB Output is correct
16 Correct 45 ms 94152 KB Output is correct
17 Correct 43 ms 94120 KB Output is correct
18 Correct 48 ms 94184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 94224 KB Output is correct
2 Correct 47 ms 94224 KB Output is correct
3 Correct 54 ms 94184 KB Output is correct
4 Correct 46 ms 94228 KB Output is correct
5 Correct 44 ms 94124 KB Output is correct
6 Correct 46 ms 94208 KB Output is correct
7 Correct 43 ms 94128 KB Output is correct
8 Correct 55 ms 94232 KB Output is correct
9 Correct 51 ms 94224 KB Output is correct
10 Correct 45 ms 94220 KB Output is correct
11 Correct 60 ms 94224 KB Output is correct
12 Correct 46 ms 94228 KB Output is correct
13 Correct 45 ms 94212 KB Output is correct
14 Correct 46 ms 94220 KB Output is correct
15 Correct 45 ms 94156 KB Output is correct
16 Correct 45 ms 94152 KB Output is correct
17 Correct 43 ms 94120 KB Output is correct
18 Correct 48 ms 94184 KB Output is correct
19 Correct 58 ms 94228 KB Output is correct
20 Correct 53 ms 94212 KB Output is correct
21 Correct 44 ms 94156 KB Output is correct
22 Correct 45 ms 94128 KB Output is correct
23 Correct 47 ms 94228 KB Output is correct
24 Correct 45 ms 94184 KB Output is correct
25 Correct 53 ms 94248 KB Output is correct
26 Correct 53 ms 94128 KB Output is correct
27 Correct 52 ms 94236 KB Output is correct
28 Correct 43 ms 94228 KB Output is correct
29 Correct 56 ms 94228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 94224 KB Output is correct
2 Correct 47 ms 94224 KB Output is correct
3 Correct 54 ms 94184 KB Output is correct
4 Correct 46 ms 94228 KB Output is correct
5 Correct 44 ms 94124 KB Output is correct
6 Correct 46 ms 94208 KB Output is correct
7 Correct 43 ms 94128 KB Output is correct
8 Correct 55 ms 94232 KB Output is correct
9 Correct 51 ms 94224 KB Output is correct
10 Correct 45 ms 94220 KB Output is correct
11 Correct 60 ms 94224 KB Output is correct
12 Correct 46 ms 94228 KB Output is correct
13 Correct 45 ms 94212 KB Output is correct
14 Correct 46 ms 94220 KB Output is correct
15 Correct 45 ms 94156 KB Output is correct
16 Correct 45 ms 94152 KB Output is correct
17 Correct 43 ms 94120 KB Output is correct
18 Correct 48 ms 94184 KB Output is correct
19 Correct 58 ms 94228 KB Output is correct
20 Correct 53 ms 94212 KB Output is correct
21 Correct 44 ms 94156 KB Output is correct
22 Correct 45 ms 94128 KB Output is correct
23 Correct 47 ms 94228 KB Output is correct
24 Correct 45 ms 94184 KB Output is correct
25 Correct 53 ms 94248 KB Output is correct
26 Correct 53 ms 94128 KB Output is correct
27 Correct 52 ms 94236 KB Output is correct
28 Correct 43 ms 94228 KB Output is correct
29 Correct 56 ms 94228 KB Output is correct
30 Correct 516 ms 168876 KB Output is correct
31 Correct 563 ms 168780 KB Output is correct
32 Correct 133 ms 102036 KB Output is correct
33 Correct 152 ms 106196 KB Output is correct
34 Correct 153 ms 106204 KB Output is correct
35 Correct 153 ms 106200 KB Output is correct
36 Correct 150 ms 106208 KB Output is correct
37 Correct 143 ms 106212 KB Output is correct
38 Correct 145 ms 106196 KB Output is correct
39 Correct 147 ms 106252 KB Output is correct
40 Correct 141 ms 106808 KB Output is correct
41 Correct 245 ms 122192 KB Output is correct
42 Correct 151 ms 106196 KB Output is correct
43 Correct 511 ms 168784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 94284 KB Output is correct
2 Correct 53 ms 94284 KB Output is correct
3 Correct 52 ms 94284 KB Output is correct
4 Correct 46 ms 94208 KB Output is correct
5 Correct 48 ms 94156 KB Output is correct
6 Correct 48 ms 94268 KB Output is correct
7 Correct 45 ms 94304 KB Output is correct
8 Correct 49 ms 94204 KB Output is correct
9 Correct 57 ms 94180 KB Output is correct
10 Correct 49 ms 94228 KB Output is correct
11 Correct 52 ms 94316 KB Output is correct
12 Correct 47 ms 94244 KB Output is correct
13 Correct 47 ms 94276 KB Output is correct
14 Correct 46 ms 94304 KB Output is correct
15 Correct 54 ms 94272 KB Output is correct
16 Correct 46 ms 94260 KB Output is correct
17 Correct 48 ms 94240 KB Output is correct
18 Correct 46 ms 94212 KB Output is correct
19 Correct 50 ms 94304 KB Output is correct
20 Correct 44 ms 94284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 94224 KB Output is correct
2 Correct 47 ms 94224 KB Output is correct
3 Correct 54 ms 94184 KB Output is correct
4 Correct 46 ms 94228 KB Output is correct
5 Correct 44 ms 94124 KB Output is correct
6 Correct 46 ms 94208 KB Output is correct
7 Correct 43 ms 94128 KB Output is correct
8 Correct 55 ms 94232 KB Output is correct
9 Correct 51 ms 94224 KB Output is correct
10 Correct 45 ms 94220 KB Output is correct
11 Correct 60 ms 94224 KB Output is correct
12 Correct 46 ms 94228 KB Output is correct
13 Correct 45 ms 94212 KB Output is correct
14 Correct 46 ms 94220 KB Output is correct
15 Correct 45 ms 94156 KB Output is correct
16 Correct 45 ms 94152 KB Output is correct
17 Correct 43 ms 94120 KB Output is correct
18 Correct 48 ms 94184 KB Output is correct
19 Correct 58 ms 94228 KB Output is correct
20 Correct 53 ms 94212 KB Output is correct
21 Correct 44 ms 94156 KB Output is correct
22 Correct 45 ms 94128 KB Output is correct
23 Correct 47 ms 94228 KB Output is correct
24 Correct 45 ms 94184 KB Output is correct
25 Correct 53 ms 94248 KB Output is correct
26 Correct 53 ms 94128 KB Output is correct
27 Correct 52 ms 94236 KB Output is correct
28 Correct 43 ms 94228 KB Output is correct
29 Correct 56 ms 94228 KB Output is correct
30 Correct 516 ms 168876 KB Output is correct
31 Correct 563 ms 168780 KB Output is correct
32 Correct 133 ms 102036 KB Output is correct
33 Correct 152 ms 106196 KB Output is correct
34 Correct 153 ms 106204 KB Output is correct
35 Correct 153 ms 106200 KB Output is correct
36 Correct 150 ms 106208 KB Output is correct
37 Correct 143 ms 106212 KB Output is correct
38 Correct 145 ms 106196 KB Output is correct
39 Correct 147 ms 106252 KB Output is correct
40 Correct 141 ms 106808 KB Output is correct
41 Correct 245 ms 122192 KB Output is correct
42 Correct 151 ms 106196 KB Output is correct
43 Correct 511 ms 168784 KB Output is correct
44 Correct 49 ms 94284 KB Output is correct
45 Correct 53 ms 94284 KB Output is correct
46 Correct 52 ms 94284 KB Output is correct
47 Correct 46 ms 94208 KB Output is correct
48 Correct 48 ms 94156 KB Output is correct
49 Correct 48 ms 94268 KB Output is correct
50 Correct 45 ms 94304 KB Output is correct
51 Correct 49 ms 94204 KB Output is correct
52 Correct 57 ms 94180 KB Output is correct
53 Correct 49 ms 94228 KB Output is correct
54 Correct 52 ms 94316 KB Output is correct
55 Correct 47 ms 94244 KB Output is correct
56 Correct 47 ms 94276 KB Output is correct
57 Correct 46 ms 94304 KB Output is correct
58 Correct 54 ms 94272 KB Output is correct
59 Correct 46 ms 94260 KB Output is correct
60 Correct 48 ms 94240 KB Output is correct
61 Correct 46 ms 94212 KB Output is correct
62 Correct 50 ms 94304 KB Output is correct
63 Correct 44 ms 94284 KB Output is correct
64 Correct 355 ms 168956 KB Output is correct
65 Correct 392 ms 175988 KB Output is correct
66 Correct 370 ms 173564 KB Output is correct
67 Correct 369 ms 175332 KB Output is correct
68 Correct 74 ms 102364 KB Output is correct
69 Correct 92 ms 102080 KB Output is correct
70 Correct 104 ms 102304 KB Output is correct
71 Correct 77 ms 102416 KB Output is correct
72 Correct 70 ms 102000 KB Output is correct
73 Correct 72 ms 102076 KB Output is correct
74 Correct 146 ms 112992 KB Output is correct
75 Correct 169 ms 112956 KB Output is correct
76 Correct 482 ms 175656 KB Output is correct
77 Correct 505 ms 175540 KB Output is correct
78 Correct 342 ms 161740 KB Output is correct
79 Correct 383 ms 162148 KB Output is correct
80 Correct 139 ms 108724 KB Output is correct
81 Correct 411 ms 180132 KB Output is correct
82 Correct 330 ms 180360 KB Output is correct
83 Correct 392 ms 175520 KB Output is correct
84 Correct 359 ms 175076 KB Output is correct
85 Correct 355 ms 175460 KB Output is correct
86 Correct 367 ms 174180 KB Output is correct
87 Correct 381 ms 178464 KB Output is correct
88 Correct 349 ms 176912 KB Output is correct
89 Correct 390 ms 175656 KB Output is correct
90 Correct 368 ms 173732 KB Output is correct
91 Correct 414 ms 173876 KB Output is correct
92 Correct 563 ms 172816 KB Output is correct