Submission #40281

# Submission time Handle Problem Language Result Execution time Memory
40281 2018-01-30T15:28:41 Z jackyliuxx Ancient Books (IOI17_books) C++14
0 / 100
0 ms 2020 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;

long long minimum_walk(std::vector<int> p, int s) {
    int ans = 0;
    int n = p.size();
    vector<int> group(n);
    for (int i = 0; i < n; i++) {
        group[i] = i;
    }
    for (int i = 0; i < n; i++) {
        if (group[i] == i) {
            int x = i;
            while (p[x] != i) {
                ans += abs(p[x] - x);
                x = p[x];
                group[x] = i;
            }
            ans += abs(p[x] - x);
        }
    }
    vector<int> end(n, -1);
    for (int i = 0; i < n; i++) {
        end[group[i]] = max(end[group[i]], i);
    }
    int min_group = 0;
    for (int i = 0; i < n; i++) {
        if (min_group == -1) {
            ans += 2;
            min_group = i;
        } else {
            end[min_group] = max(end[min_group], end[group[i]]);
            group[i] = min_group;
        }
        if (i == end[min_group]) {
            min_group = -1;
        }
    }
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2020 KB Output is correct
2 Correct 0 ms 2020 KB Output is correct
3 Correct 0 ms 2020 KB Output is correct
4 Correct 0 ms 2020 KB Output is correct
5 Incorrect 0 ms 2020 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2020 KB Output is correct
2 Correct 0 ms 2020 KB Output is correct
3 Correct 0 ms 2020 KB Output is correct
4 Correct 0 ms 2020 KB Output is correct
5 Incorrect 0 ms 2020 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2020 KB Output is correct
2 Correct 0 ms 2020 KB Output is correct
3 Correct 0 ms 2020 KB Output is correct
4 Correct 0 ms 2020 KB Output is correct
5 Incorrect 0 ms 2020 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2020 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2020 KB Output is correct
2 Correct 0 ms 2020 KB Output is correct
3 Correct 0 ms 2020 KB Output is correct
4 Correct 0 ms 2020 KB Output is correct
5 Incorrect 0 ms 2020 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -