답안 #47301

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
47301 2018-04-30T12:12:19 Z TAMREF Roller Coaster Railroad (IOI16_railroad) C++11
64 / 100
385 ms 115364 KB
#include "railroad.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int mx = 4e5 + 5;

ll dp[16][1<<16];
vector<int> X;
vector<int> O[mx];
int deg[mx];
bool vis[mx];

void dfs(int x){
    vis[x] = 1;
    for(int &u : O[x]){
        if(!vis[u]) dfs(u);
    }
}

ll plan_roller_coaster(vector<int> s, vector<int> t) {
    int n = (int) s.size();

    if(n > 16)
    {
        for(int i = 0; i < n; i++){
            X.push_back(s[i]);
            X.push_back(t[i]);
        }
        sort(X.begin(),X.end());
        X.erase(unique(X.begin(),X.end()),X.end());
        for(int i = 0; i < n; i++){
            s[i] = lower_bound(X.begin(),X.end(),s[i]) - X.begin();
            t[i] = lower_bound(X.begin(),X.end(),t[i]) - X.begin();
            ++deg[ s[i] ];
            --deg[ t[i] ];
            O[ s[i] ].push_back(t[i]);
        }
        for(int i = 0; i < X.size(); i++){
            int cnt = (i == 0) - deg[i];
            if(cnt > 0){
                deg[i] += cnt;
                deg[i+1] -= cnt;
                O[i].push_back(i+1);
            }else if(cnt < 0) return 42;
        }
        dfs(0);
        for(int i = 0; i < X.size(); i++) if(!vis[i]) return 42;
        return 0;
    }
    for(int i = 0; i < n; i++) fill(dp[i], dp[i] + (1 << n), LLONG_MAX);
    for(int i = 0; i < n; i++) dp[i][1<<i] = 0;

    for(int b = 1; b < (1 << n); b++){
        for(int i = 0; i < n; i++){
            if(!(b >> i & 1)) continue;
            for(int j = 0; j < n; j++){
                if(b >> j & 1) continue;
                ll &d = dp[j][b | (1 << j)];
                d = min(d, dp[i][b] + max(0, t[i]-s[j]));
            }
        }
    }
    ll ans = LLONG_MAX;
    for(int i = 0; i < n; i++){
        ans = min(ans, dp[i][(1<<n)-1]);
    }
    return ans;
}

Compilation message

railroad.cpp: In function 'll plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:39:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < X.size(); i++){
                        ~~^~~~~~~~~~
railroad.cpp:48:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < X.size(); i++) if(!vis[i]) return 42;
                        ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 9720 KB n = 2
2 Correct 9 ms 9720 KB n = 2
3 Correct 9 ms 9884 KB n = 2
4 Correct 9 ms 9884 KB n = 2
5 Correct 9 ms 9884 KB n = 2
6 Correct 9 ms 9888 KB n = 2
7 Correct 9 ms 10016 KB n = 3
8 Correct 9 ms 10016 KB n = 3
9 Correct 9 ms 10092 KB n = 3
10 Correct 10 ms 10092 KB n = 8
11 Correct 9 ms 10092 KB n = 8
12 Correct 9 ms 10092 KB n = 8
13 Correct 9 ms 10092 KB n = 8
14 Correct 9 ms 10092 KB n = 8
15 Correct 9 ms 10092 KB n = 8
16 Correct 11 ms 10092 KB n = 8
17 Correct 10 ms 10092 KB n = 8
18 Correct 9 ms 10092 KB n = 8
19 Correct 9 ms 10092 KB n = 3
20 Correct 9 ms 10092 KB n = 7
21 Correct 10 ms 10092 KB n = 8
22 Correct 9 ms 10092 KB n = 8
23 Correct 9 ms 10092 KB n = 8
24 Correct 9 ms 10092 KB n = 8
25 Correct 8 ms 10092 KB n = 8
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 9720 KB n = 2
2 Correct 9 ms 9720 KB n = 2
3 Correct 9 ms 9884 KB n = 2
4 Correct 9 ms 9884 KB n = 2
5 Correct 9 ms 9884 KB n = 2
6 Correct 9 ms 9888 KB n = 2
7 Correct 9 ms 10016 KB n = 3
8 Correct 9 ms 10016 KB n = 3
9 Correct 9 ms 10092 KB n = 3
10 Correct 10 ms 10092 KB n = 8
11 Correct 9 ms 10092 KB n = 8
12 Correct 9 ms 10092 KB n = 8
13 Correct 9 ms 10092 KB n = 8
14 Correct 9 ms 10092 KB n = 8
15 Correct 9 ms 10092 KB n = 8
16 Correct 11 ms 10092 KB n = 8
17 Correct 10 ms 10092 KB n = 8
18 Correct 9 ms 10092 KB n = 8
19 Correct 9 ms 10092 KB n = 3
20 Correct 9 ms 10092 KB n = 7
21 Correct 10 ms 10092 KB n = 8
22 Correct 9 ms 10092 KB n = 8
23 Correct 9 ms 10092 KB n = 8
24 Correct 9 ms 10092 KB n = 8
25 Correct 8 ms 10092 KB n = 8
26 Correct 9 ms 10092 KB n = 8
27 Correct 9 ms 10092 KB n = 8
28 Correct 8 ms 10092 KB n = 8
29 Correct 55 ms 18228 KB n = 16
30 Correct 52 ms 18228 KB n = 16
31 Correct 52 ms 18228 KB n = 16
32 Correct 52 ms 18228 KB n = 16
33 Correct 53 ms 18228 KB n = 16
34 Correct 53 ms 18228 KB n = 16
35 Correct 51 ms 18228 KB n = 16
36 Correct 29 ms 18228 KB n = 15
37 Correct 9 ms 18228 KB n = 8
38 Correct 54 ms 18228 KB n = 16
39 Correct 52 ms 18228 KB n = 16
40 Correct 9 ms 18228 KB n = 9
41 Correct 53 ms 18228 KB n = 16
42 Correct 54 ms 18236 KB n = 16
43 Correct 53 ms 18236 KB n = 16
44 Correct 9 ms 18236 KB n = 9
45 Correct 29 ms 18236 KB n = 15
46 Correct 52 ms 18236 KB n = 16
47 Correct 53 ms 18236 KB n = 16
48 Correct 54 ms 18236 KB n = 16
# 결과 실행 시간 메모리 Grader output
1 Correct 345 ms 41708 KB n = 199999
2 Correct 261 ms 41708 KB n = 199991
3 Correct 253 ms 41708 KB n = 199993
4 Correct 270 ms 41708 KB n = 152076
5 Correct 155 ms 41708 KB n = 93249
6 Correct 305 ms 44820 KB n = 199910
7 Correct 335 ms 52928 KB n = 199999
8 Correct 309 ms 52928 KB n = 199997
9 Correct 320 ms 55092 KB n = 171294
10 Correct 251 ms 55092 KB n = 140872
11 Correct 345 ms 59700 KB n = 199886
12 Correct 321 ms 67564 KB n = 199996
13 Correct 315 ms 68096 KB n = 200000
14 Correct 241 ms 68096 KB n = 199998
15 Correct 237 ms 68096 KB n = 200000
16 Correct 243 ms 68096 KB n = 199998
17 Correct 263 ms 71496 KB n = 200000
18 Correct 248 ms 74588 KB n = 190000
19 Correct 281 ms 94436 KB n = 177777
20 Correct 169 ms 94436 KB n = 100000
21 Correct 364 ms 96444 KB n = 200000
22 Correct 280 ms 96444 KB n = 200000
23 Correct 385 ms 111324 KB n = 200000
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 9720 KB n = 2
2 Correct 9 ms 9720 KB n = 2
3 Correct 9 ms 9884 KB n = 2
4 Correct 9 ms 9884 KB n = 2
5 Correct 9 ms 9884 KB n = 2
6 Correct 9 ms 9888 KB n = 2
7 Correct 9 ms 10016 KB n = 3
8 Correct 9 ms 10016 KB n = 3
9 Correct 9 ms 10092 KB n = 3
10 Correct 10 ms 10092 KB n = 8
11 Correct 9 ms 10092 KB n = 8
12 Correct 9 ms 10092 KB n = 8
13 Correct 9 ms 10092 KB n = 8
14 Correct 9 ms 10092 KB n = 8
15 Correct 9 ms 10092 KB n = 8
16 Correct 11 ms 10092 KB n = 8
17 Correct 10 ms 10092 KB n = 8
18 Correct 9 ms 10092 KB n = 8
19 Correct 9 ms 10092 KB n = 3
20 Correct 9 ms 10092 KB n = 7
21 Correct 10 ms 10092 KB n = 8
22 Correct 9 ms 10092 KB n = 8
23 Correct 9 ms 10092 KB n = 8
24 Correct 9 ms 10092 KB n = 8
25 Correct 8 ms 10092 KB n = 8
26 Correct 9 ms 10092 KB n = 8
27 Correct 9 ms 10092 KB n = 8
28 Correct 8 ms 10092 KB n = 8
29 Correct 55 ms 18228 KB n = 16
30 Correct 52 ms 18228 KB n = 16
31 Correct 52 ms 18228 KB n = 16
32 Correct 52 ms 18228 KB n = 16
33 Correct 53 ms 18228 KB n = 16
34 Correct 53 ms 18228 KB n = 16
35 Correct 51 ms 18228 KB n = 16
36 Correct 29 ms 18228 KB n = 15
37 Correct 9 ms 18228 KB n = 8
38 Correct 54 ms 18228 KB n = 16
39 Correct 52 ms 18228 KB n = 16
40 Correct 9 ms 18228 KB n = 9
41 Correct 53 ms 18228 KB n = 16
42 Correct 54 ms 18236 KB n = 16
43 Correct 53 ms 18236 KB n = 16
44 Correct 9 ms 18236 KB n = 9
45 Correct 29 ms 18236 KB n = 15
46 Correct 52 ms 18236 KB n = 16
47 Correct 53 ms 18236 KB n = 16
48 Correct 54 ms 18236 KB n = 16
49 Correct 345 ms 41708 KB n = 199999
50 Correct 261 ms 41708 KB n = 199991
51 Correct 253 ms 41708 KB n = 199993
52 Correct 270 ms 41708 KB n = 152076
53 Correct 155 ms 41708 KB n = 93249
54 Correct 305 ms 44820 KB n = 199910
55 Correct 335 ms 52928 KB n = 199999
56 Correct 309 ms 52928 KB n = 199997
57 Correct 320 ms 55092 KB n = 171294
58 Correct 251 ms 55092 KB n = 140872
59 Correct 345 ms 59700 KB n = 199886
60 Correct 321 ms 67564 KB n = 199996
61 Correct 315 ms 68096 KB n = 200000
62 Correct 241 ms 68096 KB n = 199998
63 Correct 237 ms 68096 KB n = 200000
64 Correct 243 ms 68096 KB n = 199998
65 Correct 263 ms 71496 KB n = 200000
66 Correct 248 ms 74588 KB n = 190000
67 Correct 281 ms 94436 KB n = 177777
68 Correct 169 ms 94436 KB n = 100000
69 Correct 364 ms 96444 KB n = 200000
70 Correct 280 ms 96444 KB n = 200000
71 Correct 385 ms 111324 KB n = 200000
72 Correct 348 ms 115364 KB n = 200000
73 Incorrect 267 ms 115364 KB answer is not correct: 42 instead of 34382661743
74 Halted 0 ms 0 KB -