Submission #1012207

# Submission time Handle Problem Language Result Execution time Memory
1012207 2024-07-01T19:46:59 Z hyakup Ancient Books (IOI17_books) C++17
50 / 100
111 ms 14108 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], especial[maxn];
int bit[maxn];

void update( int id, int val ){ for( int i = id + 1; i < maxn; i += i&-i ) bit[i] += val; }
int query( int id ){ int sum = 0; for( int i = id + 1; i > 0; i -= i&-i ) sum += bit[i]; return sum; }

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 ){
		bool good = false;
		if( i > maxi ){
			if( maxi != -1 ) resp += 2LL*(i - maxi);
			good = true;
		}
		ll cur = i;
		int aux = query(i);
		while( !marc[cur] ){
			maxi = max( maxi, cur );
			marc[cur] = true;
			if( query(cur) != aux ) good = true;
			cur = p[cur];
		}
		if( i <= s && s <= maxi ) contido = true;

		if( good ){
			cur = i;
			while( !especial[cur] ){
				especial[cur] = true;
				update( cur, 1 );
				cur = p[cur];
			}
		}
	}

	ll l = s, r = s;
	while( l >= 0 && !especial[l] ) l--;
	while( r < n && !especial[r] ) r++;
	if( contido ) resp += 2LL*min( s - l, r - s );
	else{
		if( l == -1 ) resp += 2LL*(r - s);
		else if( r == n ) resp += 2LL*(s - l);
	}
	return resp;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2556 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2556 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2556 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 105 ms 14108 KB Output is correct
31 Correct 111 ms 14092 KB Output is correct
32 Correct 58 ms 8184 KB Output is correct
33 Correct 81 ms 14072 KB Output is correct
34 Correct 82 ms 13904 KB Output is correct
35 Correct 81 ms 13908 KB Output is correct
36 Correct 95 ms 14068 KB Output is correct
37 Correct 93 ms 13904 KB Output is correct
38 Correct 94 ms 14076 KB Output is correct
39 Correct 87 ms 13904 KB Output is correct
40 Correct 97 ms 13912 KB Output is correct
41 Correct 111 ms 14088 KB Output is correct
42 Correct 108 ms 13904 KB Output is correct
43 Correct 75 ms 13648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3590'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2556 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 105 ms 14108 KB Output is correct
31 Correct 111 ms 14092 KB Output is correct
32 Correct 58 ms 8184 KB Output is correct
33 Correct 81 ms 14072 KB Output is correct
34 Correct 82 ms 13904 KB Output is correct
35 Correct 81 ms 13908 KB Output is correct
36 Correct 95 ms 14068 KB Output is correct
37 Correct 93 ms 13904 KB Output is correct
38 Correct 94 ms 14076 KB Output is correct
39 Correct 87 ms 13904 KB Output is correct
40 Correct 97 ms 13912 KB Output is correct
41 Correct 111 ms 14088 KB Output is correct
42 Correct 108 ms 13904 KB Output is correct
43 Correct 75 ms 13648 KB Output is correct
44 Incorrect 1 ms 2396 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3590'
45 Halted 0 ms 0 KB -