제출 #67063

#제출 시각아이디문제언어결과실행 시간메모리
67063InovakRoller Coaster Railroad (IOI16_railroad)C++14
34 / 100
282 ms14944 KiB
#include "railroad.h" #include <bits/stdc++.h> #define fr first #define sc second #define ll long long #define mk make_pair #define pb push_back #define sz(s) s.size() #define all(s) s.begin(), s.end() using namespace std; const int N = 2e5+10; const ll inf = 1e16+7; struct node { int a, b, c; }; node a[N], c[N]; int b[N], d[N], lb[N]; int t[N*4]; bool cmp(node a, node b) { if(lb[a.c] > lb[b.c]) return 1; if(lb[a.c] == lb[b.c] && a.a < b.a) return 1; return 0; } bool cmp2(node a, node b) { return (a.a < b.a); } void build(int v, int tl, int tr) { if(tl == tr) { t[v] = c[tl].c; } else { int tm = (tl + tr) / 2; build(v + v, tl, tm); build(v + v + 1, tm + 1, tr); t[v] = t[v + v]; if(b[t[v]] > b[t[v + v + 1]]) t[v] = t[v + v + 1]; } } void update(int v, int tl, int tr, int pos) { if(tl = tr) { t[v] = 0; } else { int tm = (tl + tr) / 2; if(pos <= tm) update(v + v, tl, tm, pos); else update(v + v + 1, tm + 1, tr, pos); t[v] = t[v + v]; if(b[t[v]] > b[t[v + v + 1]]) t[v] = t[v + v + 1]; } } int get(int v, int tl, int tr, int l, int r) { if(tl > r || tr < l || tr < tl || l > r) return 0; if(tl >= l && r >= tr) { return t[v]; } int tm = (tl + tr) / 2; int in = get(v + v, tl, tm, l, r); int id = get(v + v + 1, tm + 1, tr, l, r); if(b[in] < b[id]) return in; return id; } ll dp[70000][20]; long long plan_roller_coaster(vector<int> s, vector<int> t) { int n = (int) s.size(); b[0] = n+10; if(n <= 16) { memset(dp, inf, sizeof(dp)); for(int i = 1; i < (1 << n); i++) { if(__builtin_popcount(i) == 1) { for(int j = 0; j < n; j++) { if(i & (1 << j)) { dp[i][j] = 0; } } continue; } for(int j = 0; j < n; j++) { for(int k = 0; k < n; k++) { if(j != k) { if((i & (1 << j)) && (i & (1 << k))) { ll o = max(0, t[k] - s[j]); dp[i][j] = min(dp[i][j], dp[i ^ (1 << j)][k] + o); } } } } } ll ans = inf; for(int i = 0; i < n; i++) { ans = min(ans, dp[(1 << n) - 1][i]); } return ans; } for(int i = 0; i < n; i++) { a[i+1].a = s[i]; a[i+1].b = t[i]; a[i+1].c = i+1; c[i+1] = a[i+1]; } sort(c + 1, c + n + 1, &cmp2); for(int i = 1; i <= n; i++) { int l = 0, r = n + 1; while(r - l > 1) { int m = (l + r) / 2; if(c[m].a >= a[i].b) r = m; else l = m; } lb[a[i].c] = r; } sort(a + 1, a + n + 1, &cmp); for(int i = 1; i <= n; i++) b[a[i].c] = d[c[i].c] = i; build(1, 1, n); int cnt = 1, in = 1; vector <pair <int, int> > ch; ch.pb(mk(a[in].a, a[in].b)); while(cnt < n) { update(1, 1, n, d[a[in].c]); int l = 0, r = n + 1; while(r - l > 1) { int m = (l + r) / 2; if(c[m].a >= a[in].b) r = m; else l = m; } int o = get(1, 1, n, r, n); if(o == 0) break; update(1, 1, n, o); cnt++; in = o; ch.pb(mk(a[in].a, a[in].b)); } if(cnt < n) return 1; bool fl = 0; for(int i = 0; i < sz(ch) - 1; i++) { if(ch[i + 1].fr < ch[i].sc) fl = 1; } return fl; } //int main() { // int n; // cin >> n; // vector <int> s, t; // for(int i = 0, x; i < n; i++) { // cin >> x; // s.pb(x); // cin >> x; // t.pb(x); // } // cout << plan_roller_coaster(s, t) << endl; //}

컴파일 시 표준 에러 (stderr) 메시지

railroad.cpp: In function 'void update(int, int, int, int)':
railroad.cpp:50:11: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
     if(tl = tr) {
        ~~~^~~~
railroad.cpp: In function 'long long int plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:83:35: warning: overflow in implicit constant conversion [-Woverflow]
         memset(dp, inf, sizeof(dp));
                                   ^
railroad.cpp:151:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < sz(ch) - 1; i++) {
                    ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...