Submission #1012192

# Submission time Handle Problem Language Result Execution time Memory
1012192 2024-07-01T19:27:29 Z hyakup Ancient Books (IOI17_books) C++17
50 / 100
120 ms 9232 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
#define bug(x) cout << #x << " " << x << endl;
#define ll long long

const ll maxn = 1e6 + 10;

bool marc[maxn];

long long minimum_walk(vector<int> p, int s) {
	if( is_sorted( p.begin(), p.end() ) ) return 0;
	ll n = (ll)p.size();
	ll resp = 0;
	for( ll i = 0; i < (ll)p.size(); i++ ) resp += (ll)abs(p[i] - i);
	ll maxi = -1;
	bool contido = false;
	for( ll i = 0; i < n; i++ ){
		if( !marc[i] && p[i] != i ){
			if( maxi != -1 && i > maxi ) resp += 2LL*(i - maxi);
			ll cur = i;
			while( !marc[cur] ){
				maxi = max( maxi, cur );
				marc[cur] = true;
				cur = p[cur];
			}
			if( i <= s && s <= maxi ) contido = true;
		}
	}
	if( contido ){
		ll desloc = 2*maxn;
		for( int i = 0; i < n; i++ ) if( marc[i] ) desloc = min( desloc, 2LL*abs(i - s));
		return resp + desloc;
	}
	bool ok = true;
	for( int i = s; i >= 0; i-- ) if( marc[i] ) ok = false;
	if( ok ){
		ll desloc = 2*maxn;
		for( int i = s; i < n; i++ ) if( marc[i] ) desloc = min( desloc, 2LL*abs(i - s));
		return resp + desloc;
	}
	ok = true;
	for( int i = s; i < n; i++ ) if( marc[i] ) ok = false;
	if( ok ){
		ll desloc = 2*maxn;
		for( int i = s; i >= 0; i-- ) if( marc[i] ) desloc = min( desloc, 2LL*abs(i - s));
		return resp + desloc;
	}
	return resp;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 116 ms 9220 KB Output is correct
31 Correct 75 ms 9232 KB Output is correct
32 Correct 54 ms 8204 KB Output is correct
33 Correct 81 ms 9224 KB Output is correct
34 Correct 73 ms 9044 KB Output is correct
35 Correct 89 ms 9200 KB Output is correct
36 Correct 120 ms 9216 KB Output is correct
37 Correct 70 ms 9212 KB Output is correct
38 Correct 89 ms 9220 KB Output is correct
39 Correct 78 ms 9208 KB Output is correct
40 Correct 81 ms 9208 KB Output is correct
41 Correct 85 ms 9228 KB Output is correct
42 Correct 82 ms 9208 KB Output is correct
43 Correct 72 ms 9204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 504 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 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 116 ms 9220 KB Output is correct
31 Correct 75 ms 9232 KB Output is correct
32 Correct 54 ms 8204 KB Output is correct
33 Correct 81 ms 9224 KB Output is correct
34 Correct 73 ms 9044 KB Output is correct
35 Correct 89 ms 9200 KB Output is correct
36 Correct 120 ms 9216 KB Output is correct
37 Correct 70 ms 9212 KB Output is correct
38 Correct 89 ms 9220 KB Output is correct
39 Correct 78 ms 9208 KB Output is correct
40 Correct 81 ms 9208 KB Output is correct
41 Correct 85 ms 9228 KB Output is correct
42 Correct 82 ms 9208 KB Output is correct
43 Correct 72 ms 9204 KB Output is correct
44 Incorrect 0 ms 504 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -