답안 #826918

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
826918 2023-08-16T06:39:17 Z vnm06 고대 책들 (IOI17_books) C++14
0 / 100
1 ms 340 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;
    }
}

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);
    Le=pr[0].first;
    Ri=pr[0].second;
    for(int i=1; i<bri; i++)
    {
        if(pr[i].first>Ri)
        {
            ans+=2;
            Le=pr[i].first;
            Ri=pr[i].second;
        }
        else if(pr[i].second<=Ri) Ri=pr[i].second;
    }
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 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 Incorrect 1 ms 308 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 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 Incorrect 1 ms 308 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 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 Incorrect 1 ms 308 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4072'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 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 Incorrect 1 ms 308 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -