Submission #764514

#TimeUsernameProblemLanguageResultExecution timeMemory
764514marvinthangShortcut (IOI16_shortcut)C++17
71 / 100
2076 ms1748 KiB
/************************************* * author: marvinthang * * created: 23.06.2023 20:12:10 * *************************************/ #include "shortcut.h" #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define left ___left #define right ___right #define TIME (1.0 * clock() / CLOCKS_PER_SEC) #define MASK(i) (1LL << (i)) #define BIT(x, i) ((x) >> (i) & 1) #define __builtin_popcount __builtin_popcountll #define ALL(v) (v).begin(), (v).end() #define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i) #define REPD(i, n) for (int i = (n); i--; ) #define FOR(i, a, b) for (int i = (a), _b = (b); i < _b; ++i) #define FORD(i, b, a) for (int i = (b), _a = (a); --i >= _a; ) #define FORE(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORDE(i, b, a) for (int i = (b), _a = (a); i >= _a; --i) #define scan_op(...) istream & operator >> (istream &in, __VA_ARGS__ &u) #define print_op(...) ostream & operator << (ostream &out, const __VA_ARGS__ &u) #ifdef LOCAL #include "debug.h" #else #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } #define DB(...) 23 #define db(...) 23 #define debug(...) 23 #endif template <class U, class V> scan_op(pair <U, V>) { return in >> u.first >> u.second; } template <class T> scan_op(vector <T>) { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; } template <class U, class V> print_op(pair <U, V>) { return out << '(' << u.first << ", " << u.second << ')'; } template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")"; else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); } template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); } template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; } template <class A, class B> bool minimize(A &a, B b) { if (a > b) { a = b; return true; } return false; } template <class A, class B> bool maximize(A &a, B b) { if (a < b) { a = b; return true; } return false; } // end of template const int MAX = 1e6 + 6; const long long INF = 1e9 * MAX; long long find_shortcut(int n, vector <int> l, vector <int> d, int c) { vector <long long> x(n); REP(i, n - 1) x[i + 1] = x[i] + l[i]; auto check = [&] (long long f) { long long max_diff = INF, min_diff = -INF, max_sum = INF, min_sum = -INF; REP(r, n) REP(l, r) { long long k = f - d[r] - d[l]; if (x[r] - x[l] <= k) continue; k -= c; if (k < 0) return false; minimize(max_diff, x[r] - x[l] + k); maximize(min_diff, x[r] - x[l] - k); minimize(max_sum, x[l] + x[r] + k); maximize(min_sum, x[l] + x[r] - k); } REP(i, n) REP(j, n) if (min_diff <= x[i] - x[j] && x[i] - x[j] <= max_diff && min_sum <= x[i] + x[j] && x[i] + x[j] <= max_sum) return true; return false; }; long long ll = *max_element(ALL(d)); long long rr = x[n - 1] + 2 * ll; while (ll <= rr) { long long m = ll + rr >> 1; if (check(m)) rr = m - 1; else ll = m + 1; } return ll; } #ifdef LOCAL #include <cstdio> #include <cassert> #include "shortcut.h" int main() { file("shortcut"); int n, c; assert(2 == scanf("%d%d", &n, &c)); std::vector<int> l(n - 1); std::vector<int> d(n); for (int i = 0; i < n - 1; i++) assert(1 == scanf("%d", &l[i])); for (int i = 0; i < n; i++) assert(1 == scanf("%d", &d[i])); long long t = find_shortcut(n, l, d, c); printf("%lld\n", t); return 0; } #endif

Compilation message (stderr)

shortcut.cpp: In function 'long long int find_shortcut(int, std::vector<int>, std::vector<int>, int)':
shortcut.cpp:72:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   72 |         long long m = ll + rr >> 1;
      |                       ~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...