답안 #42713

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
42713 2018-03-03T02:29:33 Z funcsr Roller Coaster Railroad (IOI16_railroad) C++14
34 / 100
415 ms 38580 KB
#include "railroad.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define INF (1LL<<60)
#define INF2 1145141919
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define index(x, y) (int)(lower_bound(all(x), y) - x.begin())
#define pb push_back
#define _1 first
#define _2 second
#define MAX_N (1<<19)
struct SegTree {
  P seg[MAX_N*2-1];
  SegTree() {
    rep(i, MAX_N*2-1) seg[i] = P(INF2, -1);
  }
  void update(int k, P v) {
    k += MAX_N-1;
    seg[k] = v;
    while (k > 0) {
      k = (k-1)/2;
      seg[k] = min(seg[k*2+1], seg[k*2+2]);
    }
  }
  P query(int a, int b, int k=0, int l=0, int r=MAX_N) {
    if (b <= l || r <= a) return P(INF2, -1);
    if (a <= l && r <= b) return seg[k];
    return min(query(a, b, k*2+1, l, (l+r)/2), query(a, b, k*2+2, (l+r)/2, r));
  }
} rmq;

int N;
int S[200000], T[200000];
long long dp[1<<16][16];
vector<int> G[400000];

bool f() {
  vector<int> xs;
  rep(i, N) xs.pb(S[i]), xs.pb(T[i]);
  sort(all(xs)); uniq(xs);
  rep(i, N) G[index(xs, S[i])].pb(T[i]);
  rep(i, xs.size()) sort(all(G[i]), greater<int>());
  rep(i, xs.size()) if (!G[i].empty()) rmq.update(i, P(G[i].back(), i));
  int s = 0;
  rep(_, N) {
    int p = rmq.query(s, MAX_N)._2;
    if (p == -1) return false;
    s = index(xs, G[p].back());
    G[p].pop_back();
    rmq.update(p, P(INF2, -1));
    if (!G[p].empty()) rmq.update(p, P(G[p].back(), p));
  }
  return true;
}

long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
  N = s.size();
  rep(i, N) S[i] = s[i], T[i] = t[i];
  //if( false){
  if (N <= 16) {
    rep(i, 1<<N) rep(j, N) dp[i][j] = INF;
    rep(i, N) dp[1<<i][i] = 0;
    rep(b, 1<<N) {
      rep(last, N) {
        if (dp[b][last] == INF) continue;
        rep(t, N) if (((b>>t)&1) == 0) {
          dp[b|(1<<t)][t] = min(dp[b|(1<<t)][t], dp[b][last] + max(T[last]-S[t], 0));
        }
      }
    }
    long long m = INF;
    rep(i, N) m = min(m, dp[(1<<N)-1][i]);
    return m;
  }
  else {
    return !f();
  }
}

Compilation message

railroad.cpp: In function 'bool f()':
railroad.cpp:8:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i, n) for (int i=0; i<(n); i++)
                                  ^
railroad.cpp:48:3: note: in expansion of macro 'rep'
   rep(i, xs.size()) sort(all(G[i]), greater<int>());
   ^
railroad.cpp:8:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i, n) for (int i=0; i<(n); i++)
                                  ^
railroad.cpp:49:3: note: in expansion of macro 'rep'
   rep(i, xs.size()) if (!G[i].empty()) rmq.update(i, P(G[i].back(), i));
   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 17912 KB n = 2
2 Correct 17 ms 18020 KB n = 2
3 Correct 17 ms 18088 KB n = 2
4 Correct 16 ms 18088 KB n = 2
5 Correct 16 ms 18088 KB n = 2
6 Correct 18 ms 18088 KB n = 2
7 Correct 16 ms 18088 KB n = 3
8 Correct 18 ms 18088 KB n = 3
9 Correct 16 ms 18088 KB n = 3
10 Correct 17 ms 18212 KB n = 8
11 Correct 17 ms 18212 KB n = 8
12 Correct 16 ms 18212 KB n = 8
13 Correct 16 ms 18216 KB n = 8
14 Correct 16 ms 18232 KB n = 8
15 Correct 17 ms 18232 KB n = 8
16 Correct 16 ms 18232 KB n = 8
17 Correct 16 ms 18232 KB n = 8
18 Correct 16 ms 18232 KB n = 8
19 Correct 18 ms 18232 KB n = 3
20 Correct 16 ms 18232 KB n = 7
21 Correct 17 ms 18232 KB n = 8
22 Correct 16 ms 18232 KB n = 8
23 Correct 17 ms 18232 KB n = 8
24 Correct 16 ms 18232 KB n = 8
25 Correct 16 ms 18232 KB n = 8
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 17912 KB n = 2
2 Correct 17 ms 18020 KB n = 2
3 Correct 17 ms 18088 KB n = 2
4 Correct 16 ms 18088 KB n = 2
5 Correct 16 ms 18088 KB n = 2
6 Correct 18 ms 18088 KB n = 2
7 Correct 16 ms 18088 KB n = 3
8 Correct 18 ms 18088 KB n = 3
9 Correct 16 ms 18088 KB n = 3
10 Correct 17 ms 18212 KB n = 8
11 Correct 17 ms 18212 KB n = 8
12 Correct 16 ms 18212 KB n = 8
13 Correct 16 ms 18216 KB n = 8
14 Correct 16 ms 18232 KB n = 8
15 Correct 17 ms 18232 KB n = 8
16 Correct 16 ms 18232 KB n = 8
17 Correct 16 ms 18232 KB n = 8
18 Correct 16 ms 18232 KB n = 8
19 Correct 18 ms 18232 KB n = 3
20 Correct 16 ms 18232 KB n = 7
21 Correct 17 ms 18232 KB n = 8
22 Correct 16 ms 18232 KB n = 8
23 Correct 17 ms 18232 KB n = 8
24 Correct 16 ms 18232 KB n = 8
25 Correct 16 ms 18232 KB n = 8
26 Correct 16 ms 18232 KB n = 8
27 Correct 17 ms 18232 KB n = 8
28 Correct 17 ms 18232 KB n = 8
29 Correct 63 ms 26348 KB n = 16
30 Correct 77 ms 26348 KB n = 16
31 Correct 80 ms 26392 KB n = 16
32 Correct 64 ms 26472 KB n = 16
33 Correct 64 ms 26472 KB n = 16
34 Correct 72 ms 26472 KB n = 16
35 Correct 64 ms 26472 KB n = 16
36 Correct 49 ms 26472 KB n = 15
37 Correct 17 ms 26472 KB n = 8
38 Correct 61 ms 26472 KB n = 16
39 Correct 61 ms 26472 KB n = 16
40 Correct 17 ms 26472 KB n = 9
41 Correct 66 ms 26500 KB n = 16
42 Correct 63 ms 26500 KB n = 16
43 Correct 63 ms 26500 KB n = 16
44 Correct 16 ms 26500 KB n = 9
45 Correct 38 ms 26500 KB n = 15
46 Correct 62 ms 26500 KB n = 16
47 Correct 60 ms 26500 KB n = 16
48 Correct 62 ms 26500 KB n = 16
# 결과 실행 시간 메모리 Grader output
1 Correct 415 ms 30800 KB n = 199999
2 Correct 355 ms 34680 KB n = 199991
3 Correct 260 ms 38580 KB n = 199993
4 Incorrect 299 ms 38580 KB answer is not correct: 1 instead of 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 17912 KB n = 2
2 Correct 17 ms 18020 KB n = 2
3 Correct 17 ms 18088 KB n = 2
4 Correct 16 ms 18088 KB n = 2
5 Correct 16 ms 18088 KB n = 2
6 Correct 18 ms 18088 KB n = 2
7 Correct 16 ms 18088 KB n = 3
8 Correct 18 ms 18088 KB n = 3
9 Correct 16 ms 18088 KB n = 3
10 Correct 17 ms 18212 KB n = 8
11 Correct 17 ms 18212 KB n = 8
12 Correct 16 ms 18212 KB n = 8
13 Correct 16 ms 18216 KB n = 8
14 Correct 16 ms 18232 KB n = 8
15 Correct 17 ms 18232 KB n = 8
16 Correct 16 ms 18232 KB n = 8
17 Correct 16 ms 18232 KB n = 8
18 Correct 16 ms 18232 KB n = 8
19 Correct 18 ms 18232 KB n = 3
20 Correct 16 ms 18232 KB n = 7
21 Correct 17 ms 18232 KB n = 8
22 Correct 16 ms 18232 KB n = 8
23 Correct 17 ms 18232 KB n = 8
24 Correct 16 ms 18232 KB n = 8
25 Correct 16 ms 18232 KB n = 8
26 Correct 16 ms 18232 KB n = 8
27 Correct 17 ms 18232 KB n = 8
28 Correct 17 ms 18232 KB n = 8
29 Correct 63 ms 26348 KB n = 16
30 Correct 77 ms 26348 KB n = 16
31 Correct 80 ms 26392 KB n = 16
32 Correct 64 ms 26472 KB n = 16
33 Correct 64 ms 26472 KB n = 16
34 Correct 72 ms 26472 KB n = 16
35 Correct 64 ms 26472 KB n = 16
36 Correct 49 ms 26472 KB n = 15
37 Correct 17 ms 26472 KB n = 8
38 Correct 61 ms 26472 KB n = 16
39 Correct 61 ms 26472 KB n = 16
40 Correct 17 ms 26472 KB n = 9
41 Correct 66 ms 26500 KB n = 16
42 Correct 63 ms 26500 KB n = 16
43 Correct 63 ms 26500 KB n = 16
44 Correct 16 ms 26500 KB n = 9
45 Correct 38 ms 26500 KB n = 15
46 Correct 62 ms 26500 KB n = 16
47 Correct 60 ms 26500 KB n = 16
48 Correct 62 ms 26500 KB n = 16
49 Correct 415 ms 30800 KB n = 199999
50 Correct 355 ms 34680 KB n = 199991
51 Correct 260 ms 38580 KB n = 199993
52 Incorrect 299 ms 38580 KB answer is not correct: 1 instead of 0
53 Halted 0 ms 0 KB -