답안 #906343

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
906343 2024-01-14T04:40:21 Z nightfal 고대 책들 (IOI17_books) C++14
0 / 100
1 ms 360 KB
#include <cstdio>
#include <vector>
#include <cassert>
#include <cstdlib>

using namespace std;

#include <vector>

long long minimum_walk(std::vector<int> p, int s) {
    int n = p.size(), total = 0, prevIdx = 0;
    std::vector<int> v(n,0);

    for(int i=0; i<n; i++) {
        if (i==p[i]) continue;
        int idx = i;
        total += idx - prevIdx;
        // printf("prevIdx=%d, idx=%d, idx-prevIdx=%d, total=%d\n",prevIdx,idx,idx-prevIdx,total);
        while(idx!=p[idx]) {
            total += abs(p[idx]-idx);
        // printf("prevIdx=%d, idx=%d, p[%d]=%d, abs(p[%d]-idx)=%d, total=%d\n",prevIdx,idx,idx,p[idx],idx,abs(p[idx]-idx),total);
            prevIdx = idx; idx = p[idx];
            p[prevIdx] = prevIdx;
        }
        prevIdx = idx;
        // printf("prevIdx=%d, idx=%d, p[%d]=%d\n",prevIdx,idx,idx,p[idx],idx);
    }
	return total + prevIdx;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 360 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 360 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 360 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4728'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 360 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -