Submission #1080272

# Submission time Handle Problem Language Result Execution time Memory
1080272 2024-08-29T08:31:16 Z TB_ Ancient Books (IOI17_books) C++17
50 / 100
148 ms 42968 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define fo(i, n) for(ll i = 0; i<(n); i++)
#define F first
#define S second
#define pb push_back
#define deb(x) cout << #x << " = " << (x) << endl
#define deb2(x, y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl

typedef vector<ll> vl;
typedef vector<vl> vvl;


vl color, nextB, highest;
ll ans = 0, c = 0;

void dfs(int u){
    if(color[u]!=-1) return;
    highest[c]=max(highest[c], (ll)u);
    color[u] = c;
    dfs(nextB[u]);
    ans+=abs(nextB[u]-u);
}

long long minimum_walk(std::vector<int> p, int s){
    ll n = p.size();
    fo(i, n)nextB.pb(p[i]);
    color.assign(n, -1);
    ll biggest = 0;
    fo(i, n){
        if(color[i]!=-1) continue;
        if((nextB[i] != i))biggest = i+1;
        highest.pb(-1);
        dfs(i);
        c++;
    }
    ll current = 0;
    // deb(ans);
    fo(i, biggest){
        if(current<i)ans+=2;
        // deb2(current, i);
        current = max(current, highest[color[i]]);
    }

	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 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 436 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 428 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 412 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 1 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 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 436 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 428 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 412 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 1 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 432 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 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 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 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 436 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 428 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 412 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 1 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 432 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 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 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 140 ms 42820 KB Output is correct
31 Correct 148 ms 36812 KB Output is correct
32 Correct 99 ms 42832 KB Output is correct
33 Correct 104 ms 42940 KB Output is correct
34 Correct 135 ms 42968 KB Output is correct
35 Correct 102 ms 42832 KB Output is correct
36 Correct 113 ms 34520 KB Output is correct
37 Correct 89 ms 31420 KB Output is correct
38 Correct 93 ms 30652 KB Output is correct
39 Correct 96 ms 30808 KB Output is correct
40 Correct 104 ms 31196 KB Output is correct
41 Correct 115 ms 35788 KB Output is correct
42 Correct 123 ms 33048 KB Output is correct
43 Correct 101 ms 42780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 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 1 ms 348 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 436 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 428 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 412 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 1 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 432 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 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 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 140 ms 42820 KB Output is correct
31 Correct 148 ms 36812 KB Output is correct
32 Correct 99 ms 42832 KB Output is correct
33 Correct 104 ms 42940 KB Output is correct
34 Correct 135 ms 42968 KB Output is correct
35 Correct 102 ms 42832 KB Output is correct
36 Correct 113 ms 34520 KB Output is correct
37 Correct 89 ms 31420 KB Output is correct
38 Correct 93 ms 30652 KB Output is correct
39 Correct 96 ms 30808 KB Output is correct
40 Correct 104 ms 31196 KB Output is correct
41 Correct 115 ms 35788 KB Output is correct
42 Correct 123 ms 33048 KB Output is correct
43 Correct 101 ms 42780 KB Output is correct
44 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -