답안 #266847

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
266847 2020-08-15T13:29:46 Z REALITYNB Fuel Station (NOI20_fuelstation) C++14
20 / 100
384 ms 53032 KB
#include <bits/stdc++.h> 
#define int long long 
#define pii pair<long long,long long> 
#define F first 
#define S second 
#define mp make_pair
using namespace std; 
bool check(int s , vector<int>& d , vector<int>& f){
    int li = 0 , rest = s ; 
    for(int i=0;i<d.size();i++){
        if(d[i]-li>rest) return 0 ; 
        rest -= (d[i]-li) ;
        rest+=f[i] ; 
        li = d[i] ; 
    }
    return 1 ; 
}
int bs(int lw , int ur , int D , map<int,vector<pii>> s){
    int l =  lw , r = ur ; 
    vector<int> d , f ; 
    for(auto x : s){
        vector<pii> v = x.S ; 
        for(pii y : v) {
            d.push_back(y.F) ;  
            f.push_back(y.S) ; 
        }
    }
    d.push_back(D) ; 
    while(r-l-1){
        int md = (r+l)/2 ;
        if(check(md,d,f)){
            r= md ; 
        }
        else l = md  ; 
    }
    return r ; 
}
signed main(){
	ios_base::sync_with_stdio(0) ; 
	cin.tie(0) ; 
	cout.tie(0) ; 
	int n ,D; 
	cin>>n>>D ;
	//a[i] -> how much fuel he can get in the ith station 
	//b[i] -> F <= b[i] condition 
	//d[i] -> distance from start 
	//d  -> finish line
	map<int,vector<pii>> s ; 
	for(int i=0;i<n;i++){
		int f , b,d ; 
		cin>>d>>f>>b ; 
		s[b].push_back(mp(d,f)) ;  
	}
	for(auto x : s){
		vector<pii> v = x.S  ;  
		sort(v.begin(),v.end()) ; 
		s[x.F]= v ; 
	}
	multiset<int> r ; 
	multiset<pii> ur ; 
	int rest = 0  , li =  0 ; 
	r.insert(0) ; 
	ur.insert(mp(D,0)) ; 
	for(auto x : s){
		int F = x.F ; 
		vector<pii> fs = x.S ; 
		for(pii y : fs) ur.insert(y) ; 
		rest+= F-li   ; 
		auto it = r.end() ; 
		it-- ; 
		int big = *it ; 
		while(big>=(*(ur.begin())).F){
			rest+=(*ur.begin()).S  ; 
			r.insert((*ur.begin()).F) ;  
			ur.erase(ur.begin()) ; 
		}
		while(ur.size()&&(*ur.begin()).F-big<=rest){
			r.insert((*ur.begin()).F) ; 
			rest+= (*ur.begin()).S ;
			rest-= ((*ur.begin()).F-big) ; 
		    big = (*ur.begin()).F ; 
			ur.erase(ur.begin()) ; 
		}
		if(ur.empty()){
			cout << bs(li,F,D,s) ; 
			return 0 ;  
		}	
		li = F ; 
	}
	cout << D  ; 
	return 0 ; 
}

Compilation message

FuelStation.cpp: In function 'bool check(long long int, std::vector<long long int>&, std::vector<long long int>&)':
FuelStation.cpp:10:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for(int i=0;i<d.size();i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 325 ms 52896 KB Output is correct
2 Correct 325 ms 52896 KB Output is correct
3 Correct 324 ms 52952 KB Output is correct
4 Correct 321 ms 52896 KB Output is correct
5 Correct 321 ms 53024 KB Output is correct
6 Correct 323 ms 52892 KB Output is correct
7 Correct 333 ms 52888 KB Output is correct
8 Correct 363 ms 52904 KB Output is correct
9 Correct 384 ms 52892 KB Output is correct
10 Correct 334 ms 52892 KB Output is correct
11 Correct 326 ms 52896 KB Output is correct
12 Correct 339 ms 53024 KB Output is correct
13 Correct 326 ms 52956 KB Output is correct
14 Correct 319 ms 52892 KB Output is correct
15 Correct 326 ms 52900 KB Output is correct
16 Correct 325 ms 53032 KB Output is correct
17 Correct 328 ms 53024 KB Output is correct
18 Correct 354 ms 52896 KB Output is correct
19 Correct 329 ms 52892 KB Output is correct
20 Correct 345 ms 52896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 6 ms 1152 KB Output is correct
3 Incorrect 6 ms 1152 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 6 ms 1152 KB Output is correct
3 Incorrect 6 ms 1152 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Incorrect 0 ms 384 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 6 ms 1152 KB Output is correct
18 Incorrect 6 ms 1152 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 325 ms 52896 KB Output is correct
17 Correct 325 ms 52896 KB Output is correct
18 Correct 324 ms 52952 KB Output is correct
19 Correct 321 ms 52896 KB Output is correct
20 Correct 321 ms 53024 KB Output is correct
21 Correct 323 ms 52892 KB Output is correct
22 Correct 333 ms 52888 KB Output is correct
23 Correct 363 ms 52904 KB Output is correct
24 Correct 384 ms 52892 KB Output is correct
25 Correct 334 ms 52892 KB Output is correct
26 Correct 326 ms 52896 KB Output is correct
27 Correct 339 ms 53024 KB Output is correct
28 Correct 326 ms 52956 KB Output is correct
29 Correct 319 ms 52892 KB Output is correct
30 Correct 326 ms 52900 KB Output is correct
31 Correct 325 ms 53032 KB Output is correct
32 Correct 328 ms 53024 KB Output is correct
33 Correct 354 ms 52896 KB Output is correct
34 Correct 329 ms 52892 KB Output is correct
35 Correct 345 ms 52896 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 6 ms 1152 KB Output is correct
38 Incorrect 6 ms 1152 KB Output isn't correct
39 Halted 0 ms 0 KB -