답안 #638776

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
638776 2022-09-07T12:26:44 Z qwerasdfzxcl 고대 책들 (IOI17_books) C++17
0 / 100
1 ms 316 KB
#include "books.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int a[1001000], n, s;
bool visited[1001000];

ll myabs(ll x){
    if (x<0) return -x;
    return x;
}

ll solve(int l, int r){
    ll ret = 0;
    int mx = l;

    for (int i=l;i<=mx;i++) if (!visited[i]){
        for (int j=i;!visited[j];j=a[j]){
            visited[j] = 1;
            ret += myabs(j - a[j]);
            mx = max(mx, j);
        }
    }

    return ret + (mx<r ? solve(mx+1, r)+2 : 0);
}

long long minimum_walk(std::vector<int> P, int S) {
    n = P.size();
	for (int i=1;i<=n;i++) a[i] = P[i-1] + 1;
	s = S+1;

	return solve(1, n);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 220 KB Output is correct
2 Correct 0 ms 220 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Incorrect 0 ms 216 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 220 KB Output is correct
2 Correct 0 ms 220 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Incorrect 0 ms 216 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 220 KB Output is correct
2 Correct 0 ms 220 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Incorrect 0 ms 216 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 220 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 220 KB Output is correct
2 Correct 0 ms 220 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Incorrect 0 ms 216 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -