답안 #826928

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
826928 2023-08-16T06:56:18 Z vnm06 고대 책들 (IOI17_books) C++14
50 / 100
95 ms 28540 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;
        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;
        else if(s<=pr[i].second && s>=pr[i].first) ans+=2;
    }
    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 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 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 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 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 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 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 87 ms 13020 KB Output is correct
31 Correct 89 ms 13028 KB Output is correct
32 Correct 95 ms 28540 KB Output is correct
33 Correct 92 ms 23408 KB Output is correct
34 Correct 89 ms 23408 KB Output is correct
35 Correct 94 ms 20852 KB Output is correct
36 Correct 81 ms 15984 KB Output is correct
37 Correct 74 ms 13312 KB Output is correct
38 Correct 75 ms 13044 KB Output is correct
39 Correct 74 ms 13048 KB Output is correct
40 Correct 78 ms 12916 KB Output is correct
41 Correct 85 ms 12932 KB Output is correct
42 Correct 82 ms 12912 KB Output is correct
43 Correct 88 ms 18764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2748'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 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 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 87 ms 13020 KB Output is correct
31 Correct 89 ms 13028 KB Output is correct
32 Correct 95 ms 28540 KB Output is correct
33 Correct 92 ms 23408 KB Output is correct
34 Correct 89 ms 23408 KB Output is correct
35 Correct 94 ms 20852 KB Output is correct
36 Correct 81 ms 15984 KB Output is correct
37 Correct 74 ms 13312 KB Output is correct
38 Correct 75 ms 13044 KB Output is correct
39 Correct 74 ms 13048 KB Output is correct
40 Correct 78 ms 12916 KB Output is correct
41 Correct 85 ms 12932 KB Output is correct
42 Correct 82 ms 12912 KB Output is correct
43 Correct 88 ms 18764 KB Output is correct
44 Incorrect 0 ms 340 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2748'
45 Halted 0 ms 0 KB -