Submission #906358

# Submission time Handle Problem Language Result Execution time Memory
906358 2024-01-14T06:21:15 Z nightfal Ancient Books (IOI17_books) C++14
0 / 100
1 ms 348 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(), prevI = 0;
    long long total = 0;
    std::vector<int> v(n,0);

    for(int i=0; i<n; i++) {
        if (i==p[i]) continue;
        total += i - prevI; 
        // printf("i=%d, prevI=%d, i-prevI=%d, total=%d\n",i,prevI,i-prevI,total);
        prevI = i;
        total += abs(p[i]-i);
        // printf("i=%d, p[%d]=%d, abs(p[%d]-%d)=%d, total=%d\n",i,i,p[i],i,i,abs(p[i]-i),total);

        int idx=p[i]; p[i]=i;
        while(idx!=i) {
            total += abs(p[idx]-idx); 
        // printf("idx=%d, p[%d]=%d, abs(p[%d]-%d)=%d, total=%d\n",idx,idx,p[idx],idx,idx,abs(p[idx]-idx),total);
            int prevIdx = idx; 
            idx = p[idx];
            p[prevIdx] = prevIdx;
        }
        // printf("prevI=%d\n",prevI);
    }
	return total + prevI;
}
# Verdict Execution time Memory Grader output
1 Correct 0 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 348 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 -
# Verdict Execution time Memory Grader output
1 Correct 0 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 348 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 -
# Verdict Execution time Memory Grader output
1 Correct 0 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 348 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 -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4728'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 348 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 -