Submission #826922

# Submission time Handle Problem Language Result Execution time Memory
826922 2023-08-16T06:47:16 Z vnm06 Ancient Books (IOI17_books) C++14
50 / 100
103 ms 35380 KB
#include<bits/stdc++.h>
#include "books.h"
using namespace std;

int n;
bool used[1000005];
int a[1000005];
long long ans=0;
int bri=0, Le, Ri;
pair<int, int> pr[1000005];

void dfs(int i)
{
    while(1)
    {
        used[i]=1;
        long long st=a[i]-i;
        if(st<0) st=-st;
        ans+=st;
        if(a[i]==Le) break;
        ///cout<<i<<" "<<ans<<endl;
        i=a[i];
        if(i>Ri) Ri=i;
    }
}

int tbr=0;
int rm[1000005][2];

long long minimum_walk(std::vector<int> p, int s)
{
    n=p.size();
    for(int i=0; i<n; i++) a[i]=p[i];
    for(int i=0; i<n; i++)
    {
        if(!used[i])
        {
            Le=Ri=i;
            dfs(i);
            pr[bri]={Le, Ri};
            bri++;
        }
    }
    ///cout<<ans<<endl;
    sort(pr, pr+bri);
    rm[0][0]=pr[0].first;
    rm[0][1]=pr[0].second;
    tbr=1;
    for(int i=1; i<bri; i++)
    {
        if(pr[i].first>rm[tbr-1][1])
        {
            rm[tbr][0]=pr[i].first;
            rm[tbr][1]=pr[i].second;
            tbr++;
        }
        else if(pr[i].second>=rm[tbr-1][1]) rm[tbr-1][1]=pr[i].second;
    }
    ans+=2*(tbr-1);
    for(int i=0; i<tbr; i++)
    {
        if(s<=rm[i][1]) break;
        if(rm[i][0]!=rm[i][1]) break;
        ans-=2;
    }
    for(int i=tbr-1; i>=0; i--)
    {
        if(s>=rm[i][0]) break;
        if(rm[i][0]!=rm[i][1]) break;
        ans-=2;
    }
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 304 KB Output is correct
8 Correct 0 ms 304 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 304 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 308 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 304 KB Output is correct
8 Correct 0 ms 304 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 304 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 308 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 304 KB Output is correct
8 Correct 0 ms 304 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 304 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 308 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 86 ms 19744 KB Output is correct
31 Correct 87 ms 19680 KB Output is correct
32 Correct 95 ms 35380 KB Output is correct
33 Correct 92 ms 30052 KB Output is correct
34 Correct 95 ms 30156 KB Output is correct
35 Correct 91 ms 27492 KB Output is correct
36 Correct 85 ms 22760 KB Output is correct
37 Correct 75 ms 20048 KB Output is correct
38 Correct 74 ms 19808 KB Output is correct
39 Correct 75 ms 19788 KB Output is correct
40 Correct 78 ms 19660 KB Output is correct
41 Correct 103 ms 19684 KB Output is correct
42 Correct 84 ms 19684 KB Output is correct
43 Correct 89 ms 25456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 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 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 304 KB Output is correct
8 Correct 0 ms 304 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 304 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 308 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 86 ms 19744 KB Output is correct
31 Correct 87 ms 19680 KB Output is correct
32 Correct 95 ms 35380 KB Output is correct
33 Correct 92 ms 30052 KB Output is correct
34 Correct 95 ms 30156 KB Output is correct
35 Correct 91 ms 27492 KB Output is correct
36 Correct 85 ms 22760 KB Output is correct
37 Correct 75 ms 20048 KB Output is correct
38 Correct 74 ms 19808 KB Output is correct
39 Correct 75 ms 19788 KB Output is correct
40 Correct 78 ms 19660 KB Output is correct
41 Correct 103 ms 19684 KB Output is correct
42 Correct 84 ms 19684 KB Output is correct
43 Correct 89 ms 25456 KB Output is correct
44 Incorrect 0 ms 340 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -