Submission #640929

# Submission time Handle Problem Language Result Execution time Memory
640929 2022-09-15T14:53:21 Z piOOE Shortcut (IOI16_shortcut) C++17
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
#include "shortcut.h"

using namespace std;
using ll = long long;

ll find_shortcut(int n, vector<int> l, vector<int> d, int c) {
    vector<ll> pref(n);
    for (int i = 0; i < n - 1; ++i) {
        pref[i + 1] = pref[i] + l[i];
    }

    auto dist = [&](int i, int j) -> long long {
        if (i > j) swap(i, j);
        return pref[j] - pref[i];
    };

    constexpr ll inf = 1e18;
    ll low = 0, high = inf;
    while (low + 1 < high) {
        ll mid = (low + high) >> 1;
        auto check = [&]() -> bool {
            vector<vector<int>> cant(n), mx_pref(n), mx_suf(n);
            vector<int> prefix;
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    if (i != j && dist(i, j) + d[i] + d[j] > mid) {
                        cant[i].push_back(j);
                    }
                }
                if (!cant[i].empty()) {
                    if (cant[i][0] < i && cant[i].back() > i) {
                        return false;
                    }
                    if (cant[i][0] > i) {
                        prefix.push_back(i);
                        mx_pref[i].resize(cant[i].size());
                        mx_suf[i].resize(cant[i].size());
                        for (int j = 0; j < cant[i].size(); ++j) {
                            if (j == 0 || d[cant[i][j]] > dist(cant[i][j], mx_pref[i][j - 1])) {
                                mx_pref[i][j] = cant[i][j];
                            } else {
                                mx_pref[i][j] = mx_pref[i][j - 1];
                            }
                        }
                        for (int j = cant[i].size() - 1; j > -1; --j) {
                            if (j == cant[i].size() - 1 || d[cant[i][j]] > dist(cant[i][j], mx_suf[i][j + 1])) {
                                mx_suf[i][j] = cant[i][j];
                            } else {
                                mx_suf[i][j] = mx_suf[i][j + 1];
                            }
                        }
                    }
                }
            }
            for (int p = 0; p < n; ++p) {
                int L = 0, R = n;
                for (int i: prefix) {
                    ll D = dist(p, i) + d[i];
                    int l = -1, r = n;
                    while (l + 1 < r) {
                        int m = (l + r) >> 1;
                        auto it = lower_bound(cant[i].begin(), cant[i].end(), m) - cant[i].begin();
                        if (it == cant[i].size() || D + dist(m, mx_suf[i][it]) + d[mx_suf[i][it]] + c <= mid) {
                            r = m;
                        } else {
                            l = m;
                        }
                    }
                    L = max(L, r);
                    l = -1, r = n;
                    while (l + 1 < r) {
                        int m = (l + r) >> 1;
                        auto it = upper_bound(cant[i].begin(), cant[i].end(), m) - cant[i].begin();
                        if (it == 0 || D + dist(m, mx_pref[i][it - 1]) + d[mx_pref[i][it - 1]] + c <= mid) {
                            l = m;
                        } else {
                            r = m;
                        }
                    }
                    R = min(R, r);
                    if (L >= R) {
                        break;
                    }
                }
                if (L < R) {
                    return true;
                }
            }
            return false;
        };
        if (check()) {
            high = mid;
        } else {
            low = mid;
        }
    }
    return high;
}

Compilation message

shortcut.cpp: In lambda function:
shortcut.cpp:39:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |                         for (int j = 0; j < cant[i].size(); ++j) {
      |                                         ~~^~~~~~~~~~~~~~~~
shortcut.cpp:47:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |                             if (j == cant[i].size() - 1 || d[cant[i][j]] > dist(cant[i][j], mx_suf[i][j + 1])) {
      |                                 ~~^~~~~~~~~~~~~~~~~~~~~
shortcut.cpp:64:32: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |                         if (it == cant[i].size() || D + dist(m, mx_suf[i][it]) + d[mx_suf[i][it]] + c <= mid) {
      |                             ~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 300 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 304 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 1 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 296 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 304 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 284 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 296 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 340 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 3189 vs contestant 3019
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 300 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 304 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 1 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 296 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 304 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 284 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 296 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 340 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 3189 vs contestant 3019
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 300 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 304 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 1 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 296 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 304 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 284 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 296 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 340 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 3189 vs contestant 3019
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 300 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 304 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 1 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 296 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 304 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 284 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 296 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 340 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 3189 vs contestant 3019
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 300 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 304 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 1 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 296 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 304 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 284 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 296 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 340 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 3189 vs contestant 3019
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 300 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 304 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 1 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 296 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 304 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 284 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 296 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 340 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 3189 vs contestant 3019
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 300 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 304 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 1 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 296 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 304 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 284 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 296 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 340 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 3189 vs contestant 3019
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 300 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 304 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 1 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 296 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 304 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 284 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 296 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 340 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 3189 vs contestant 3019
19 Halted 0 ms 0 KB -