Submission #892424

# Submission time Handle Problem Language Result Execution time Memory
892424 2023-12-25T10:34:27 Z abcvuitunggio Ancient Books (IOI17_books) C++17
50 / 100
199 ms 77392 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
int vis[1000001],l[1000001];
vector <pair <int, pair <int, int>>> e;
vector <int> ve[1000001];
int f(int i){
    return (l[i]==i?i:l[i]=f(l[i]));
}
int unite(int i, int j){
    i=f(i);
    j=f(j);
    if (i==j)
        return 0;
    l[j]=i;
    return 1;
}
long long minimum_walk(vector <int> p, int s){
    int x=0,n=p.size();
    iota(l,l+n,0);
    long long d=0;
    for (int i=0;i<n;i++){
        if (!vis[i]){
            int x=i;
            while (true){
                vis[x]=1;
                ve[i].push_back(x);
                unite(x,i);
                d+=abs(x-p[x]);
                x=p[x];
                if (x==i)
                    break;
            }
        }
    }
    vector <pair <int, int>> tmp;
    for (int i=0;i<n;i++){
        if (ve[i].empty()||(ve[i].size()==1&&i!=s))
            continue;
        sort(ve[i].begin(),ve[i].end());
        tmp.push_back({ve[i][0],ve[i].back()});
    }
    sort(tmp.begin(),tmp.end());
    int cur=0;
    for (auto [l,r]:tmp){
        x+=max(l-cur,0);
        cur=max(cur,r);
    }
    return x*2+d;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 25180 KB Output is correct
2 Correct 5 ms 25176 KB Output is correct
3 Correct 5 ms 25224 KB Output is correct
4 Correct 5 ms 25180 KB Output is correct
5 Correct 6 ms 25216 KB Output is correct
6 Correct 5 ms 25180 KB Output is correct
7 Correct 5 ms 25180 KB Output is correct
8 Correct 5 ms 25180 KB Output is correct
9 Correct 5 ms 25180 KB Output is correct
10 Correct 6 ms 25180 KB Output is correct
11 Correct 6 ms 25432 KB Output is correct
12 Correct 5 ms 25176 KB Output is correct
13 Correct 5 ms 25180 KB Output is correct
14 Correct 5 ms 25180 KB Output is correct
15 Correct 5 ms 25180 KB Output is correct
16 Correct 5 ms 25180 KB Output is correct
17 Correct 5 ms 25176 KB Output is correct
18 Correct 6 ms 25180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 25180 KB Output is correct
2 Correct 5 ms 25176 KB Output is correct
3 Correct 5 ms 25224 KB Output is correct
4 Correct 5 ms 25180 KB Output is correct
5 Correct 6 ms 25216 KB Output is correct
6 Correct 5 ms 25180 KB Output is correct
7 Correct 5 ms 25180 KB Output is correct
8 Correct 5 ms 25180 KB Output is correct
9 Correct 5 ms 25180 KB Output is correct
10 Correct 6 ms 25180 KB Output is correct
11 Correct 6 ms 25432 KB Output is correct
12 Correct 5 ms 25176 KB Output is correct
13 Correct 5 ms 25180 KB Output is correct
14 Correct 5 ms 25180 KB Output is correct
15 Correct 5 ms 25180 KB Output is correct
16 Correct 5 ms 25180 KB Output is correct
17 Correct 5 ms 25176 KB Output is correct
18 Correct 6 ms 25180 KB Output is correct
19 Correct 6 ms 25432 KB Output is correct
20 Correct 5 ms 25180 KB Output is correct
21 Correct 5 ms 25180 KB Output is correct
22 Correct 5 ms 25180 KB Output is correct
23 Correct 6 ms 25192 KB Output is correct
24 Correct 6 ms 25432 KB Output is correct
25 Correct 5 ms 25180 KB Output is correct
26 Correct 5 ms 25216 KB Output is correct
27 Correct 6 ms 25176 KB Output is correct
28 Correct 5 ms 25180 KB Output is correct
29 Correct 7 ms 25220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 25180 KB Output is correct
2 Correct 5 ms 25176 KB Output is correct
3 Correct 5 ms 25224 KB Output is correct
4 Correct 5 ms 25180 KB Output is correct
5 Correct 6 ms 25216 KB Output is correct
6 Correct 5 ms 25180 KB Output is correct
7 Correct 5 ms 25180 KB Output is correct
8 Correct 5 ms 25180 KB Output is correct
9 Correct 5 ms 25180 KB Output is correct
10 Correct 6 ms 25180 KB Output is correct
11 Correct 6 ms 25432 KB Output is correct
12 Correct 5 ms 25176 KB Output is correct
13 Correct 5 ms 25180 KB Output is correct
14 Correct 5 ms 25180 KB Output is correct
15 Correct 5 ms 25180 KB Output is correct
16 Correct 5 ms 25180 KB Output is correct
17 Correct 5 ms 25176 KB Output is correct
18 Correct 6 ms 25180 KB Output is correct
19 Correct 6 ms 25432 KB Output is correct
20 Correct 5 ms 25180 KB Output is correct
21 Correct 5 ms 25180 KB Output is correct
22 Correct 5 ms 25180 KB Output is correct
23 Correct 6 ms 25192 KB Output is correct
24 Correct 6 ms 25432 KB Output is correct
25 Correct 5 ms 25180 KB Output is correct
26 Correct 5 ms 25216 KB Output is correct
27 Correct 6 ms 25176 KB Output is correct
28 Correct 5 ms 25180 KB Output is correct
29 Correct 7 ms 25220 KB Output is correct
30 Correct 199 ms 44224 KB Output is correct
31 Correct 186 ms 51392 KB Output is correct
32 Correct 128 ms 77392 KB Output is correct
33 Correct 153 ms 70216 KB Output is correct
34 Correct 127 ms 70220 KB Output is correct
35 Correct 139 ms 66256 KB Output is correct
36 Correct 122 ms 58948 KB Output is correct
37 Correct 123 ms 52792 KB Output is correct
38 Correct 134 ms 52300 KB Output is correct
39 Correct 129 ms 51924 KB Output is correct
40 Correct 144 ms 51012 KB Output is correct
41 Correct 175 ms 50652 KB Output is correct
42 Correct 164 ms 50632 KB Output is correct
43 Correct 151 ms 71636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 25180 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 5 ms 25180 KB Output is correct
2 Correct 5 ms 25176 KB Output is correct
3 Correct 5 ms 25224 KB Output is correct
4 Correct 5 ms 25180 KB Output is correct
5 Correct 6 ms 25216 KB Output is correct
6 Correct 5 ms 25180 KB Output is correct
7 Correct 5 ms 25180 KB Output is correct
8 Correct 5 ms 25180 KB Output is correct
9 Correct 5 ms 25180 KB Output is correct
10 Correct 6 ms 25180 KB Output is correct
11 Correct 6 ms 25432 KB Output is correct
12 Correct 5 ms 25176 KB Output is correct
13 Correct 5 ms 25180 KB Output is correct
14 Correct 5 ms 25180 KB Output is correct
15 Correct 5 ms 25180 KB Output is correct
16 Correct 5 ms 25180 KB Output is correct
17 Correct 5 ms 25176 KB Output is correct
18 Correct 6 ms 25180 KB Output is correct
19 Correct 6 ms 25432 KB Output is correct
20 Correct 5 ms 25180 KB Output is correct
21 Correct 5 ms 25180 KB Output is correct
22 Correct 5 ms 25180 KB Output is correct
23 Correct 6 ms 25192 KB Output is correct
24 Correct 6 ms 25432 KB Output is correct
25 Correct 5 ms 25180 KB Output is correct
26 Correct 5 ms 25216 KB Output is correct
27 Correct 6 ms 25176 KB Output is correct
28 Correct 5 ms 25180 KB Output is correct
29 Correct 7 ms 25220 KB Output is correct
30 Correct 199 ms 44224 KB Output is correct
31 Correct 186 ms 51392 KB Output is correct
32 Correct 128 ms 77392 KB Output is correct
33 Correct 153 ms 70216 KB Output is correct
34 Correct 127 ms 70220 KB Output is correct
35 Correct 139 ms 66256 KB Output is correct
36 Correct 122 ms 58948 KB Output is correct
37 Correct 123 ms 52792 KB Output is correct
38 Correct 134 ms 52300 KB Output is correct
39 Correct 129 ms 51924 KB Output is correct
40 Correct 144 ms 51012 KB Output is correct
41 Correct 175 ms 50652 KB Output is correct
42 Correct 164 ms 50632 KB Output is correct
43 Correct 151 ms 71636 KB Output is correct
44 Incorrect 5 ms 25180 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -