Submission #47299

# Submission time Handle Problem Language Result Execution time Memory
47299 2018-04-30T12:07:47 Z TAMREF Roller Coaster Railroad (IOI16_railroad) C++11
34 / 100
138 ms 29292 KB
#include "railroad.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int mx = 2e5 + 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;
                        ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4988 KB n = 2
2 Correct 5 ms 5096 KB n = 2
3 Correct 5 ms 5164 KB n = 2
4 Correct 5 ms 5164 KB n = 2
5 Correct 5 ms 5164 KB n = 2
6 Correct 5 ms 5164 KB n = 2
7 Correct 5 ms 5164 KB n = 3
8 Correct 5 ms 5164 KB n = 3
9 Correct 5 ms 5164 KB n = 3
10 Correct 6 ms 5240 KB n = 8
11 Correct 5 ms 5240 KB n = 8
12 Correct 5 ms 5240 KB n = 8
13 Correct 6 ms 5244 KB n = 8
14 Correct 6 ms 5288 KB n = 8
15 Correct 6 ms 5292 KB n = 8
16 Correct 5 ms 5292 KB n = 8
17 Correct 5 ms 5292 KB n = 8
18 Correct 5 ms 5292 KB n = 8
19 Correct 5 ms 5292 KB n = 3
20 Correct 5 ms 5292 KB n = 7
21 Correct 5 ms 5332 KB n = 8
22 Correct 5 ms 5460 KB n = 8
23 Correct 5 ms 5488 KB n = 8
24 Correct 6 ms 5488 KB n = 8
25 Correct 6 ms 5488 KB n = 8
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4988 KB n = 2
2 Correct 5 ms 5096 KB n = 2
3 Correct 5 ms 5164 KB n = 2
4 Correct 5 ms 5164 KB n = 2
5 Correct 5 ms 5164 KB n = 2
6 Correct 5 ms 5164 KB n = 2
7 Correct 5 ms 5164 KB n = 3
8 Correct 5 ms 5164 KB n = 3
9 Correct 5 ms 5164 KB n = 3
10 Correct 6 ms 5240 KB n = 8
11 Correct 5 ms 5240 KB n = 8
12 Correct 5 ms 5240 KB n = 8
13 Correct 6 ms 5244 KB n = 8
14 Correct 6 ms 5288 KB n = 8
15 Correct 6 ms 5292 KB n = 8
16 Correct 5 ms 5292 KB n = 8
17 Correct 5 ms 5292 KB n = 8
18 Correct 5 ms 5292 KB n = 8
19 Correct 5 ms 5292 KB n = 3
20 Correct 5 ms 5292 KB n = 7
21 Correct 5 ms 5332 KB n = 8
22 Correct 5 ms 5460 KB n = 8
23 Correct 5 ms 5488 KB n = 8
24 Correct 6 ms 5488 KB n = 8
25 Correct 6 ms 5488 KB n = 8
26 Correct 5 ms 5488 KB n = 8
27 Correct 5 ms 5488 KB n = 8
28 Correct 5 ms 5488 KB n = 8
29 Correct 48 ms 13436 KB n = 16
30 Correct 51 ms 13532 KB n = 16
31 Correct 50 ms 13532 KB n = 16
32 Correct 50 ms 13532 KB n = 16
33 Correct 49 ms 13532 KB n = 16
34 Correct 49 ms 13532 KB n = 16
35 Correct 51 ms 13532 KB n = 16
36 Correct 25 ms 13532 KB n = 15
37 Correct 5 ms 13532 KB n = 8
38 Correct 50 ms 13532 KB n = 16
39 Correct 48 ms 13532 KB n = 16
40 Correct 5 ms 13532 KB n = 9
41 Correct 49 ms 13532 KB n = 16
42 Correct 50 ms 13532 KB n = 16
43 Correct 53 ms 13564 KB n = 16
44 Correct 5 ms 13564 KB n = 9
45 Correct 25 ms 13564 KB n = 15
46 Correct 48 ms 13564 KB n = 16
47 Correct 48 ms 13564 KB n = 16
48 Correct 58 ms 13564 KB n = 16
# Verdict Execution time Memory Grader output
1 Runtime error 138 ms 29292 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4988 KB n = 2
2 Correct 5 ms 5096 KB n = 2
3 Correct 5 ms 5164 KB n = 2
4 Correct 5 ms 5164 KB n = 2
5 Correct 5 ms 5164 KB n = 2
6 Correct 5 ms 5164 KB n = 2
7 Correct 5 ms 5164 KB n = 3
8 Correct 5 ms 5164 KB n = 3
9 Correct 5 ms 5164 KB n = 3
10 Correct 6 ms 5240 KB n = 8
11 Correct 5 ms 5240 KB n = 8
12 Correct 5 ms 5240 KB n = 8
13 Correct 6 ms 5244 KB n = 8
14 Correct 6 ms 5288 KB n = 8
15 Correct 6 ms 5292 KB n = 8
16 Correct 5 ms 5292 KB n = 8
17 Correct 5 ms 5292 KB n = 8
18 Correct 5 ms 5292 KB n = 8
19 Correct 5 ms 5292 KB n = 3
20 Correct 5 ms 5292 KB n = 7
21 Correct 5 ms 5332 KB n = 8
22 Correct 5 ms 5460 KB n = 8
23 Correct 5 ms 5488 KB n = 8
24 Correct 6 ms 5488 KB n = 8
25 Correct 6 ms 5488 KB n = 8
26 Correct 5 ms 5488 KB n = 8
27 Correct 5 ms 5488 KB n = 8
28 Correct 5 ms 5488 KB n = 8
29 Correct 48 ms 13436 KB n = 16
30 Correct 51 ms 13532 KB n = 16
31 Correct 50 ms 13532 KB n = 16
32 Correct 50 ms 13532 KB n = 16
33 Correct 49 ms 13532 KB n = 16
34 Correct 49 ms 13532 KB n = 16
35 Correct 51 ms 13532 KB n = 16
36 Correct 25 ms 13532 KB n = 15
37 Correct 5 ms 13532 KB n = 8
38 Correct 50 ms 13532 KB n = 16
39 Correct 48 ms 13532 KB n = 16
40 Correct 5 ms 13532 KB n = 9
41 Correct 49 ms 13532 KB n = 16
42 Correct 50 ms 13532 KB n = 16
43 Correct 53 ms 13564 KB n = 16
44 Correct 5 ms 13564 KB n = 9
45 Correct 25 ms 13564 KB n = 15
46 Correct 48 ms 13564 KB n = 16
47 Correct 48 ms 13564 KB n = 16
48 Correct 58 ms 13564 KB n = 16
49 Runtime error 138 ms 29292 KB Execution killed with signal 11 (could be triggered by violating memory limits)
50 Halted 0 ms 0 KB -