Submission #1034931

# Submission time Handle Problem Language Result Execution time Memory
1034931 2024-07-25T22:11:57 Z vjudge1 Ancient Books (IOI17_books) C++17
0 / 100
0 ms 348 KB
#include "books.h"
#include<bits/stdc++.h>
using namespace std;
int par[100100];
int abp(int n){
    return par[n]?par[n]=abp(par[n]):n;
}
int merge(int a,int b){
    a=abp(a+1);b=abp(b+1);
    if(a-b)par[a]=b;
    return a!=b;
}
long long minimum_walk(std::vector<int> p, int s) {
    long long ans=0;
    int n=p.size(),K=0;
    for(int i=0;i<n;i++)if(i-p[i]) K=i,
        ans+=abs(i-p[i]),merge(i,p[i]);
    for(int i=1;i<=K;i++)
        ans+=2*merge(i-1,i);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4186'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -