|
| 1 | +#include <bits/stdc++.h> |
| 2 | +using namespace std; |
| 3 | +using ll = long long; |
| 4 | + |
| 5 | +// Template |
| 6 | +#define REP(n) for (int _=0; _<(n); _++) |
| 7 | +#define FOR(i, a, b) for (int i=a; i<(b); i++) |
| 8 | +#define F0R(i, a) for (int i=0; i<(a); i++) |
| 9 | +#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--) |
| 10 | +#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--) |
| 11 | + |
| 12 | +#define sz(x) (int)(x).size() |
| 13 | +#define all(x) x.begin(), x.end() |
| 14 | + |
| 15 | +template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } |
| 16 | +template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } |
| 17 | + |
| 18 | +namespace std { |
| 19 | + template<class Fun> |
| 20 | + class y_combinator_result { |
| 21 | + Fun fun_; |
| 22 | + public: |
| 23 | + template<class T> |
| 24 | + explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {} |
| 25 | + |
| 26 | + template<class ...Args> |
| 27 | + decltype(auto) operator()(Args &&...args) { |
| 28 | + return fun_(std::ref(*this), std::forward<Args>(args)...); |
| 29 | + } |
| 30 | + }; |
| 31 | + |
| 32 | + template<class Fun> |
| 33 | + decltype(auto) y_combinator(Fun &&fun) { |
| 34 | + return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); |
| 35 | + } |
| 36 | +} // namespace std |
| 37 | + |
| 38 | +#define DEBUG(x) cerr << #x << ": " << x << '\n' |
| 39 | +template<typename A, typename B> |
| 40 | +ostream& operator<<(ostream &os, const pair<A, B> &p) { |
| 41 | + return os << '(' << p.first << ", " << p.second << ')'; |
| 42 | +} |
| 43 | +template<typename T_container, |
| 44 | + typename T = typename enable_if<!is_same<T_container, string>::value, |
| 45 | + typename T_container::value_type>::type> |
| 46 | +ostream& operator<<(ostream &os, const T_container &v) { |
| 47 | + os << '['; string sep; |
| 48 | + for (const T &x : v) |
| 49 | + os << sep << x, sep = ", "; |
| 50 | + return os << ']'; |
| 51 | +} |
| 52 | +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); |
| 53 | + |
| 54 | +int main() { |
| 55 | + ios_base::sync_with_stdio(false); cin.tie(NULL); |
| 56 | + string line; |
| 57 | + getline(cin, line); |
| 58 | + string t; |
| 59 | + vector<ll> seeds; |
| 60 | + { |
| 61 | + stringstream ss(line.substr(7)); |
| 62 | + while (getline(ss, t, ' ')) { |
| 63 | + // cout << t << endl; |
| 64 | + seeds.push_back(stoll(t)); |
| 65 | + } |
| 66 | + } |
| 67 | + DEBUG(seeds); |
| 68 | + getline(cin, line); |
| 69 | + |
| 70 | + |
| 71 | + using P = pair<ll, ll>; |
| 72 | + using T = vector<pair<P, P>>; |
| 73 | + vector<T> V; |
| 74 | + REP(7) { |
| 75 | + getline(cin, line); |
| 76 | + |
| 77 | + T cur; |
| 78 | + while (true) { |
| 79 | + getline(cin, line); |
| 80 | + if (line.empty()) break; |
| 81 | + else { |
| 82 | + stringstream ss(line); |
| 83 | + ll x, y, d; ss >> x >> y >> d; |
| 84 | + cur.push_back({{y, y + d - 1}, {x, x + d - 1}}); |
| 85 | + } |
| 86 | + } |
| 87 | + V.push_back(cur); |
| 88 | + } |
| 89 | + |
| 90 | + cout << V << endl; |
| 91 | + |
| 92 | + auto get_pos = [&](ll x) { |
| 93 | + cout << x << ": " << endl; |
| 94 | + for (auto v: V) { |
| 95 | + ll nxt = -1; |
| 96 | + for (auto [p1, p2]: v) { |
| 97 | + auto [a, b] = p1; |
| 98 | + auto [c, d] = p2; |
| 99 | + if (a <= x && x <= b) { |
| 100 | + nxt = c + (x - a); |
| 101 | + break; |
| 102 | + } |
| 103 | + } |
| 104 | + if (nxt == -1) nxt = x; |
| 105 | + x = nxt; |
| 106 | + cout << "now " << x << endl; |
| 107 | + } |
| 108 | + return x; |
| 109 | + }; |
| 110 | + |
| 111 | + |
| 112 | + ll ans = 1e18; |
| 113 | + for (auto x: seeds) { |
| 114 | + // cout << x << ": " << get_pos(x) << endl; |
| 115 | + ckmin(ans, get_pos(x)); |
| 116 | + } |
| 117 | + cout << ans << endl; |
| 118 | +} |
0 commit comments