Submission #892436

# Submission time Handle Problem Language Result Execution time Memory
892436 2023-12-25T10:42:06 Z abcvuitunggio Ancient Books (IOI17_books) C++17
50 / 100
94 ms 18024 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
int vis[1000001],r[1000001];
vector <pair <int, pair <int, int>>> e;
long long minimum_walk(vector <int> p, int s){
    int x=0,n=p.size();
    vector <pair <int, int>> tmp;
    long long d=0;
    for (int i=0;i<n;i++){
        if (!vis[i]){
            int x=i;
            while (true){
                vis[x]=1;
                r[i]=max(r[i],x);
                d+=abs(x-p[x]);
                x=p[x];
                if (x==i)
                    break;
            }
          	if (r[i]!=i||i==s)
             	tmp.push_back({i,r[i]});
        }
    }
    sort(tmp.begin(),tmp.end());
    int cur=tmp[0].first;
    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 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 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 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 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 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 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 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 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 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 352 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 352 KB Output is correct
22 Correct 1 ms 356 KB Output is correct
23 Correct 0 ms 356 KB Output is correct
24 Correct 0 ms 352 KB Output is correct
25 Correct 1 ms 616 KB Output is correct
26 Correct 0 ms 356 KB Output is correct
27 Correct 0 ms 356 KB Output is correct
28 Correct 0 ms 360 KB Output is correct
29 Correct 0 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 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 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 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 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 352 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 352 KB Output is correct
22 Correct 1 ms 356 KB Output is correct
23 Correct 0 ms 356 KB Output is correct
24 Correct 0 ms 352 KB Output is correct
25 Correct 1 ms 616 KB Output is correct
26 Correct 0 ms 356 KB Output is correct
27 Correct 0 ms 356 KB Output is correct
28 Correct 0 ms 360 KB Output is correct
29 Correct 0 ms 356 KB Output is correct
30 Correct 93 ms 12040 KB Output is correct
31 Correct 94 ms 12128 KB Output is correct
32 Correct 78 ms 15892 KB Output is correct
33 Correct 86 ms 17516 KB Output is correct
34 Correct 84 ms 17512 KB Output is correct
35 Correct 84 ms 17784 KB Output is correct
36 Correct 85 ms 17272 KB Output is correct
37 Correct 78 ms 16336 KB Output is correct
38 Correct 81 ms 15604 KB Output is correct
39 Correct 86 ms 15352 KB Output is correct
40 Correct 80 ms 13064 KB Output is correct
41 Correct 86 ms 12040 KB Output is correct
42 Correct 84 ms 12368 KB Output is correct
43 Correct 85 ms 18024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 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 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 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 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 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 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 352 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 352 KB Output is correct
22 Correct 1 ms 356 KB Output is correct
23 Correct 0 ms 356 KB Output is correct
24 Correct 0 ms 352 KB Output is correct
25 Correct 1 ms 616 KB Output is correct
26 Correct 0 ms 356 KB Output is correct
27 Correct 0 ms 356 KB Output is correct
28 Correct 0 ms 360 KB Output is correct
29 Correct 0 ms 356 KB Output is correct
30 Correct 93 ms 12040 KB Output is correct
31 Correct 94 ms 12128 KB Output is correct
32 Correct 78 ms 15892 KB Output is correct
33 Correct 86 ms 17516 KB Output is correct
34 Correct 84 ms 17512 KB Output is correct
35 Correct 84 ms 17784 KB Output is correct
36 Correct 85 ms 17272 KB Output is correct
37 Correct 78 ms 16336 KB Output is correct
38 Correct 81 ms 15604 KB Output is correct
39 Correct 86 ms 15352 KB Output is correct
40 Correct 80 ms 13064 KB Output is correct
41 Correct 86 ms 12040 KB Output is correct
42 Correct 84 ms 12368 KB Output is correct
43 Correct 85 ms 18024 KB Output is correct
44 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -