제출 #1039158

#제출 시각아이디문제언어결과실행 시간메모리
1039158WhisperPinball (JOI14_pinball)C++17
51 / 100
1042 ms6600 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int long long #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (b); i >= (a); i --) #define REP(i, a) for (int i = 0; i < (a); ++i) #define REPD(i, a) for (int i = (a) - 1; i >= 0; --i) #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) constexpr ll LINF = (1ll << 60); constexpr int INF = (1ll << 30); constexpr int Mod = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /* Phu Trong from Nguyen Tat Thanh High School for gifted student */ template <class X, class Y> bool minimize(X &x, const Y &y){ X eps = 1e-9; if (x > y + eps) {x = y; return 1;} return 0; } template <class X, class Y> bool maximize(X &x, const Y &y){ X eps = 1e-9; if (x + eps < y) {x = y; return 1;} return 0; } int N, M; #define MAX 100005 struct Info{ int l, r, m, c; Info(){} Info(int _l, int _r, int _m, int _c): l(_l), r(_r), m(_m), c(_c){} friend istream &operator >> (istream& cin, Info& x){ cin >> x.l >> x.r >> x.m >> x.c; return cin; } } A[MAX]; vector<int> comp; int find(int x){ return lower_bound(comp.begin(), comp.end(), x) - comp.begin() + 1; } namespace SUBTASK_3{ int l[MAX], r[MAX]; bool check(void){ return (M <= 2000); } void main(void){ memset(l, 0x3f, (N + 1) * sizeof(int)); memset(r, 0x3f, (N + 1) * sizeof(int)); for (int i = 1; i <= N; ++i){ if (A[i].l == 1) l[i] = A[i].c; if (A[i].r == M) r[i] = A[i].c; for (int j = 1; j < i; ++j){ if (A[j].l < A[i].l && A[i].l <= A[j].m && A[j].m <= A[i].r){ minimize(l[i], l[j] + A[i].c); } if (A[j].r > A[i].r && A[i].l <= A[j].m && A[j].m <= A[i].r){ minimize(r[i], r[j] + A[i].c); } } } int ans = LINF; for (int i = 1; i <= N; ++i){ minimize(ans, l[i] + r[i] - A[i].c); } cout << (ans >= 1e15 ? -1 : ans); } } void process(void){ cin >> N >> M; for (int i = 1; i <= N; ++i){ cin >> A[i]; comp.push_back(A[i].l); comp.push_back(A[i].r); comp.push_back(A[i].m); } // if(SUBTASK_3 :: check()) { SUBTASK_3 :: main(); return; // } sort(comp.begin(), comp.end()); comp.resize(unique(comp.begin(), comp.end()) - comp.begin()); for (int i = 1; i <= N; ++i){ A[i].l = find(A[i].l); A[i].r = find(A[i].r); A[i].m = find(A[i].m); } } signed main(){ #define name "Whisper" cin.tie(nullptr) -> sync_with_stdio(false); //freopen(name".inp", "r", stdin); //freopen(name".out", "w", stdout); process(); return (0 ^ 0); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...