Submission #64961

# Submission time Handle Problem Language Result Execution time Memory
64961 2018-08-06T09:27:19 Z FedericoS Roller Coaster Railroad (IOI16_railroad) C++14
34 / 100
405 ms 16972 KB
#include "railroad.h"
#include <iostream>
#include <assert.h>
#include <queue>
#include <utility>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;

int N;
ll ans=1e18;
ll S[1000006],T[1000006];
ll DP[1000006][20];
priority_queue<pll> PQS,PQT;
bool V[1000006];

ll F(int b, int i){

    assert(b&(1<<i));

	if(DP[b][i]!=-1)
		return DP[b][i];

	b=b^(1<<i);

	if(!b)
		return 0;

	ll res=1e18;
	for(int j=0;j<N;j++)
		if(b&(1<<j) and j!=i)
			res=min(res,F(b,j)+max(0LL,T[j]-S[i]));

	DP[b|(1<<i)][i]=res;
	return res;

}

long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {

    N=s.size();
	for(int i=0;i<N;i++)
        S[i]=s[i];
	for(int i=0;i<N;i++)
		T[i]=t[i];

    if(N>16){

        for(int i=0;i<N;i++){
            PQS.push({S[i],i});
            PQT.push({T[i],i});
        }

        S[N]=1e18;
        T[N]=-1;
        PQS.push({S[N],N});
        PQT.push({T[N],N});

        int cont=N+1,x,y;
        while(PQS.size() and PQT.size()){

            while(V[PQS.top().second] and PQS.size())
                PQS.pop();
            while(V[PQT.top().second] and PQT.size())
                PQT.pop();

            if(PQS.empty() and PQT.empty())
                return 0;

            x=PQT.top().second;
            y=PQS.top().second;

            if(x==y)
                V[x]=true;
            else if(T[x]<=S[y]){
                V[x]=true;
                V[y]=true;
                S[cont]=S[x];
                T[cont]=T[y];
                PQS.push({S[cont],cont});
                PQT.push({T[cont],cont});
                cont++;
            }
            else
                return 1;
        }

        return 0;
    }

	int b=(1<<N)-1;

	for(int i=0;i<N;i++)
		for(int j=0;j<=b;j++)
			DP[j][i]=-1;

	for(int i=0;i<N;i++)
		ans=min(ans,F(b,i));

	return ans;

}
/*
4
1 3
3 7
10 10
20 2
*/
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB n = 2
2 Correct 4 ms 616 KB n = 2
3 Correct 3 ms 616 KB n = 2
4 Correct 3 ms 616 KB n = 2
5 Correct 3 ms 616 KB n = 2
6 Correct 2 ms 616 KB n = 2
7 Correct 2 ms 616 KB n = 3
8 Correct 2 ms 616 KB n = 3
9 Correct 2 ms 620 KB n = 3
10 Correct 2 ms 620 KB n = 8
11 Correct 3 ms 620 KB n = 8
12 Correct 2 ms 620 KB n = 8
13 Correct 2 ms 620 KB n = 8
14 Correct 3 ms 620 KB n = 8
15 Correct 2 ms 620 KB n = 8
16 Correct 3 ms 620 KB n = 8
17 Correct 3 ms 620 KB n = 8
18 Correct 4 ms 620 KB n = 8
19 Correct 4 ms 620 KB n = 3
20 Correct 2 ms 620 KB n = 7
21 Correct 2 ms 620 KB n = 8
22 Correct 3 ms 620 KB n = 8
23 Correct 3 ms 620 KB n = 8
24 Correct 3 ms 620 KB n = 8
25 Correct 2 ms 620 KB n = 8
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB n = 2
2 Correct 4 ms 616 KB n = 2
3 Correct 3 ms 616 KB n = 2
4 Correct 3 ms 616 KB n = 2
5 Correct 3 ms 616 KB n = 2
6 Correct 2 ms 616 KB n = 2
7 Correct 2 ms 616 KB n = 3
8 Correct 2 ms 616 KB n = 3
9 Correct 2 ms 620 KB n = 3
10 Correct 2 ms 620 KB n = 8
11 Correct 3 ms 620 KB n = 8
12 Correct 2 ms 620 KB n = 8
13 Correct 2 ms 620 KB n = 8
14 Correct 3 ms 620 KB n = 8
15 Correct 2 ms 620 KB n = 8
16 Correct 3 ms 620 KB n = 8
17 Correct 3 ms 620 KB n = 8
18 Correct 4 ms 620 KB n = 8
19 Correct 4 ms 620 KB n = 3
20 Correct 2 ms 620 KB n = 7
21 Correct 2 ms 620 KB n = 8
22 Correct 3 ms 620 KB n = 8
23 Correct 3 ms 620 KB n = 8
24 Correct 3 ms 620 KB n = 8
25 Correct 2 ms 620 KB n = 8
26 Correct 2 ms 620 KB n = 8
27 Correct 3 ms 620 KB n = 8
28 Correct 3 ms 620 KB n = 8
29 Correct 96 ms 10896 KB n = 16
30 Correct 130 ms 10988 KB n = 16
31 Correct 116 ms 11004 KB n = 16
32 Correct 91 ms 11004 KB n = 16
33 Correct 98 ms 11004 KB n = 16
34 Correct 113 ms 11004 KB n = 16
35 Correct 130 ms 11004 KB n = 16
36 Correct 41 ms 11004 KB n = 15
37 Correct 3 ms 11004 KB n = 8
38 Correct 89 ms 11004 KB n = 16
39 Correct 98 ms 11004 KB n = 16
40 Correct 3 ms 11004 KB n = 9
41 Correct 153 ms 11004 KB n = 16
42 Correct 102 ms 11004 KB n = 16
43 Correct 94 ms 11004 KB n = 16
44 Correct 3 ms 11004 KB n = 9
45 Correct 46 ms 11004 KB n = 15
46 Correct 111 ms 11004 KB n = 16
47 Correct 119 ms 11004 KB n = 16
48 Correct 127 ms 11004 KB n = 16
# Verdict Execution time Memory Grader output
1 Correct 384 ms 16892 KB n = 199999
2 Correct 148 ms 16892 KB n = 199991
3 Correct 141 ms 16892 KB n = 199993
4 Correct 325 ms 16892 KB n = 152076
5 Correct 165 ms 16892 KB n = 93249
6 Correct 390 ms 16972 KB n = 199910
7 Correct 341 ms 16972 KB n = 199999
8 Correct 359 ms 16972 KB n = 199997
9 Correct 343 ms 16972 KB n = 171294
10 Correct 351 ms 16972 KB n = 140872
11 Incorrect 405 ms 16972 KB answer is not correct: 0 instead of 1
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB n = 2
2 Correct 4 ms 616 KB n = 2
3 Correct 3 ms 616 KB n = 2
4 Correct 3 ms 616 KB n = 2
5 Correct 3 ms 616 KB n = 2
6 Correct 2 ms 616 KB n = 2
7 Correct 2 ms 616 KB n = 3
8 Correct 2 ms 616 KB n = 3
9 Correct 2 ms 620 KB n = 3
10 Correct 2 ms 620 KB n = 8
11 Correct 3 ms 620 KB n = 8
12 Correct 2 ms 620 KB n = 8
13 Correct 2 ms 620 KB n = 8
14 Correct 3 ms 620 KB n = 8
15 Correct 2 ms 620 KB n = 8
16 Correct 3 ms 620 KB n = 8
17 Correct 3 ms 620 KB n = 8
18 Correct 4 ms 620 KB n = 8
19 Correct 4 ms 620 KB n = 3
20 Correct 2 ms 620 KB n = 7
21 Correct 2 ms 620 KB n = 8
22 Correct 3 ms 620 KB n = 8
23 Correct 3 ms 620 KB n = 8
24 Correct 3 ms 620 KB n = 8
25 Correct 2 ms 620 KB n = 8
26 Correct 2 ms 620 KB n = 8
27 Correct 3 ms 620 KB n = 8
28 Correct 3 ms 620 KB n = 8
29 Correct 96 ms 10896 KB n = 16
30 Correct 130 ms 10988 KB n = 16
31 Correct 116 ms 11004 KB n = 16
32 Correct 91 ms 11004 KB n = 16
33 Correct 98 ms 11004 KB n = 16
34 Correct 113 ms 11004 KB n = 16
35 Correct 130 ms 11004 KB n = 16
36 Correct 41 ms 11004 KB n = 15
37 Correct 3 ms 11004 KB n = 8
38 Correct 89 ms 11004 KB n = 16
39 Correct 98 ms 11004 KB n = 16
40 Correct 3 ms 11004 KB n = 9
41 Correct 153 ms 11004 KB n = 16
42 Correct 102 ms 11004 KB n = 16
43 Correct 94 ms 11004 KB n = 16
44 Correct 3 ms 11004 KB n = 9
45 Correct 46 ms 11004 KB n = 15
46 Correct 111 ms 11004 KB n = 16
47 Correct 119 ms 11004 KB n = 16
48 Correct 127 ms 11004 KB n = 16
49 Correct 384 ms 16892 KB n = 199999
50 Correct 148 ms 16892 KB n = 199991
51 Correct 141 ms 16892 KB n = 199993
52 Correct 325 ms 16892 KB n = 152076
53 Correct 165 ms 16892 KB n = 93249
54 Correct 390 ms 16972 KB n = 199910
55 Correct 341 ms 16972 KB n = 199999
56 Correct 359 ms 16972 KB n = 199997
57 Correct 343 ms 16972 KB n = 171294
58 Correct 351 ms 16972 KB n = 140872
59 Incorrect 405 ms 16972 KB answer is not correct: 0 instead of 1
60 Halted 0 ms 0 KB -