답안 #216025

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
216025 2020-03-26T15:54:22 Z emil_physmath 고대 책들 (IOI17_books) C++17
50 / 100
192 ms 23396 KB
#include "books.h"
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

long long minimum_walk(vector<int> a, int s)
{
    int n = a.size();
    long long ans = 0;
    vector<bool> used(n);
    vector<pair<int, int> > p;
    for (int i = 0; i < n; ++i)
        if (!used[i])
        {
            int j = i;
            p.push_back({i, i});
            do {
                used[j] = true;
                j = a[j];
                p.back().second = max(p.back().second, j);
            } while(j != i);
        }
    sort(p.begin(), p.end());
    int r = 0;
    for (pair<int, int>& x: p)
        if (x.first <= r)
            r = max(r, x.second);
        else if (x.first != x.second)
        {
            ans += 2 * (x.first - r);
            // ans = max(ans, 2LL * x.first);
            r = x.second;
        }
    for (int i = 0; i < n; ++i)
        ans += abs(a[i] - i);
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 4 ms 256 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 4 ms 256 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 4 ms 256 KB Output is correct
20 Correct 4 ms 256 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 4 ms 256 KB Output is correct
25 Correct 5 ms 256 KB Output is correct
26 Correct 4 ms 256 KB Output is correct
27 Correct 4 ms 256 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 4 ms 256 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 4 ms 256 KB Output is correct
20 Correct 4 ms 256 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 4 ms 256 KB Output is correct
25 Correct 5 ms 256 KB Output is correct
26 Correct 4 ms 256 KB Output is correct
27 Correct 4 ms 256 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 187 ms 14968 KB Output is correct
31 Correct 185 ms 14968 KB Output is correct
32 Correct 192 ms 23396 KB Output is correct
33 Correct 181 ms 23396 KB Output is correct
34 Correct 183 ms 23396 KB Output is correct
35 Correct 173 ms 23396 KB Output is correct
36 Correct 170 ms 17132 KB Output is correct
37 Correct 165 ms 15604 KB Output is correct
38 Correct 190 ms 15152 KB Output is correct
39 Correct 164 ms 15224 KB Output is correct
40 Correct 170 ms 14968 KB Output is correct
41 Correct 182 ms 14968 KB Output is correct
42 Correct 176 ms 14968 KB Output is correct
43 Correct 182 ms 23372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 256 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 4 ms 256 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 4 ms 256 KB Output is correct
20 Correct 4 ms 256 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 4 ms 256 KB Output is correct
25 Correct 5 ms 256 KB Output is correct
26 Correct 4 ms 256 KB Output is correct
27 Correct 4 ms 256 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 187 ms 14968 KB Output is correct
31 Correct 185 ms 14968 KB Output is correct
32 Correct 192 ms 23396 KB Output is correct
33 Correct 181 ms 23396 KB Output is correct
34 Correct 183 ms 23396 KB Output is correct
35 Correct 173 ms 23396 KB Output is correct
36 Correct 170 ms 17132 KB Output is correct
37 Correct 165 ms 15604 KB Output is correct
38 Correct 190 ms 15152 KB Output is correct
39 Correct 164 ms 15224 KB Output is correct
40 Correct 170 ms 14968 KB Output is correct
41 Correct 182 ms 14968 KB Output is correct
42 Correct 176 ms 14968 KB Output is correct
43 Correct 182 ms 23372 KB Output is correct
44 Incorrect 5 ms 256 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -