Submission #693008

# Submission time Handle Problem Language Result Execution time Memory
693008 2023-02-02T08:47:43 Z Antekb Long Distance Coach (JOI17_coach) C++14
100 / 100
307 ms 26680 KB
#include<bits/stdc++.h>
 
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("trapv")
 
#define st first
#define nd second
#define pb push_back
#define eb emplace_back
#define pp(x) pop_back(x)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define rev(x) reverse(all(x))
#define sor(x) sort(all(x))
#define sz(x) (int)(x).size()
#define rsz(x) resize(x)
 
using namespace std;
 
///~~~~~~~~~~~~~~~~~~~~~~~~~~
 
template <typename H, typename T> 
ostream& operator<<(ostream& os, pair<H, T> m){
	return os <<"("<< m.st<<", "<<m.nd<<")";
}
template <typename H> 
ostream& operator<<(ostream& os, vector<H> V){
	os<<"{";
	for(int i=0; i<V.size(); i++){
		if(i)os<<" ";
		os<<V[i];
	}
	os<<"}";
	return os;
}
 
void debug(){cerr<<"\n";}
template <typename H, typename... T>
void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);}
#define deb(x...) cerr<<#x<<" = ";debug(x);
//#define deb(x...) ;
 
///~~~~~~~~~~~~~~~~~~~~~~~~~
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii > vii;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef string str;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

 
#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
 
const int N=1<<19, INF=1e9+5, mod=1e9+7, mod2=998244353;

struct modint{
	int n=0;
	modint(){}
	modint(ll x){
		n=x%mod;
		if(n<0)n+=mod;
	}
	operator int(){
		return n;
	}
	modint operator+(modint a){a.n = n+a.n; if(a.n>=mod)a.n-=mod;return a;}
	modint operator+=(modint a){return (*this)=(*this)+a;}
	modint operator-(modint a){a.n = n-a.n; if(a.n<0)a.n+=mod;return a;}
	modint operator-=(modint a){return (*this)=(*this)-a;}
	modint operator*(modint a){a.n = (n*1ll*a.n)%mod; return a;}
	modint operator*=(modint a){return (*this)=(*this)*a;}
	modint operator^(const ll &m)const{
		modint a(1);
		if(m==0)return a;
		if(m==1)return (*this);
		a=(*this)^(m/2);
		a*=a;
		return a*((*this)^(m&1));
	}
	modint odw(){
		return (*this)^((ll)mod-2);
	}
	modint operator/(modint a){return (*this)*a.odw();}
	modint operator/=(modint a){return (*this)=(*this)/a;}
	bool operator==(modint a){return a.n==n;}
	friend ostream& operator<<(ostream& os, modint m) {
		return os << m.n; 
	}
};
modint fact[N], fact2[N];
typedef vector<modint> vm;
void factinit(){
    fact[0]=1;
    for(int i=1; i<N; i++){
        fact[i]=(fact[i-1]*modint(i))%mod;
    }
    fact2[N-1]=fact[N-1].odw();
    for(int i=N-2; i>=0; i--){
    	fact2[i]=(fact2[i+1]*modint(i+1))%mod;
    }
}
modint npok(int _n, int _k){
    return fact[_n]*fact2[_k]*fact2[_n-_k];
}
ll dp[N];
int fir[N], res[N], C[N];
ll pref[N];
int main(){
	//factinit();
	//BOOST;
	ll x;
	int n, m, w, t;
	cin>>x>>n>>m>>w>>t;
	vl V(n);
	vii V2(m);
	for(ll &i:V)cin>>i;
	for(auto &i:V2)cin>>i.st>>i.nd;
	sor(V);
	sor(V2);
	fir[0]=-1;
	for(int i=0; i<m; i++){
		res[i+1]=V2[i].st;
		C[i+1]=V2[i].nd;
		fir[i+1]=-1;
		pref[i+1]=pref[i]+C[i+1];
	}
	V.pb(x);
	for(int i=n; i>=0; i--){
		fir[upper_bound(res, res+m+1, V[i]%t)-res-1]=i;
	}
	dp[0]=w*(x/t+1);
	deb(dp[0]);
	vector<pair<ll, ll> > V3;
	vector<ld> opt;
	opt.pb(0);
	V3.eb(0, dp[0]);
	for(int i=1; i<=m; i++){
		dp[i]=dp[i-1]+w*ll((x-res[i])/t+1)-C[i];
		//deb(i, dp[i]);
		if(fir[i]+1){
			dp[i]-=w*ll(V[fir[i]]/t)*i;
			//for(int j=0; j<i; j++){dp[i]=min(dp[i], dp[j]-w*ll(V[fir[i]]/t)*j);}
			int k=upper_bound(all(opt), V[fir[i]]/t)-opt.begin();
			for(int j=max(0, k-5); j<V3.size() && j<=k+5; j++)dp[i]=min(dp[i], V3[j].st*(V[fir[i]]/t)+V3[j].nd);
			dp[i]+=w*ll(V[fir[i]]/t)*i;
		}
		//deb(dp[i])
		ll A=-i*ll(w), B=dp[i];
		//deb(A, B);
		while(V3.size()){
			ll A2=V3.back().st, B2=V3.back().nd;
			//deb(A2, B2);
			if(A*opt.back()+B<A2*opt.back()+B2){
				V3.pp();
				opt.pp();
			}
			else{
				ld y=(B2-B)/(A-A2);
				opt.pb(y);
				V3.eb(A, B);
				break;
			}
		}
		if(!V3.size()){
			V3.eb(A, B);
			opt.pb(0);
		}
	}
	cout<<dp[m]+pref[m];
}

Compilation message

coach.cpp: In function 'int main()':
coach.cpp:157:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  157 |    for(int j=max(0, k-5); j<V3.size() && j<=k+5; j++)dp[i]=min(dp[i], V3[j].st*(V[fir[i]]/t)+V3[j].nd);
      |                           ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4436 KB Output is correct
2 Correct 2 ms 4436 KB Output is correct
3 Correct 2 ms 4436 KB Output is correct
4 Correct 3 ms 4436 KB Output is correct
5 Correct 2 ms 4436 KB Output is correct
6 Correct 2 ms 4436 KB Output is correct
7 Correct 2 ms 4436 KB Output is correct
8 Correct 2 ms 4436 KB Output is correct
9 Correct 2 ms 4436 KB Output is correct
10 Correct 2 ms 4436 KB Output is correct
11 Correct 2 ms 4436 KB Output is correct
12 Correct 2 ms 4436 KB Output is correct
13 Correct 2 ms 4436 KB Output is correct
14 Correct 2 ms 4436 KB Output is correct
15 Correct 2 ms 4436 KB Output is correct
16 Correct 2 ms 4436 KB Output is correct
17 Correct 2 ms 4436 KB Output is correct
18 Correct 2 ms 4436 KB Output is correct
19 Correct 2 ms 4436 KB Output is correct
20 Correct 3 ms 4436 KB Output is correct
21 Correct 2 ms 4436 KB Output is correct
22 Correct 2 ms 4436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4436 KB Output is correct
2 Correct 2 ms 4436 KB Output is correct
3 Correct 2 ms 4436 KB Output is correct
4 Correct 3 ms 4436 KB Output is correct
5 Correct 2 ms 4436 KB Output is correct
6 Correct 2 ms 4436 KB Output is correct
7 Correct 2 ms 4436 KB Output is correct
8 Correct 2 ms 4436 KB Output is correct
9 Correct 2 ms 4436 KB Output is correct
10 Correct 2 ms 4436 KB Output is correct
11 Correct 2 ms 4436 KB Output is correct
12 Correct 2 ms 4436 KB Output is correct
13 Correct 2 ms 4436 KB Output is correct
14 Correct 2 ms 4436 KB Output is correct
15 Correct 2 ms 4436 KB Output is correct
16 Correct 2 ms 4436 KB Output is correct
17 Correct 2 ms 4436 KB Output is correct
18 Correct 2 ms 4436 KB Output is correct
19 Correct 2 ms 4436 KB Output is correct
20 Correct 3 ms 4436 KB Output is correct
21 Correct 2 ms 4436 KB Output is correct
22 Correct 2 ms 4436 KB Output is correct
23 Correct 2 ms 4436 KB Output is correct
24 Correct 2 ms 4436 KB Output is correct
25 Correct 2 ms 4436 KB Output is correct
26 Correct 2 ms 4436 KB Output is correct
27 Correct 2 ms 4436 KB Output is correct
28 Correct 2 ms 4436 KB Output is correct
29 Correct 2 ms 4436 KB Output is correct
30 Correct 2 ms 4436 KB Output is correct
31 Correct 2 ms 4436 KB Output is correct
32 Correct 2 ms 4436 KB Output is correct
33 Correct 2 ms 4436 KB Output is correct
34 Correct 2 ms 4436 KB Output is correct
35 Correct 2 ms 4440 KB Output is correct
36 Correct 2 ms 4436 KB Output is correct
37 Correct 2 ms 4436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4436 KB Output is correct
2 Correct 2 ms 4436 KB Output is correct
3 Correct 2 ms 4436 KB Output is correct
4 Correct 3 ms 4436 KB Output is correct
5 Correct 2 ms 4436 KB Output is correct
6 Correct 2 ms 4436 KB Output is correct
7 Correct 2 ms 4436 KB Output is correct
8 Correct 2 ms 4436 KB Output is correct
9 Correct 2 ms 4436 KB Output is correct
10 Correct 2 ms 4436 KB Output is correct
11 Correct 2 ms 4436 KB Output is correct
12 Correct 2 ms 4436 KB Output is correct
13 Correct 2 ms 4436 KB Output is correct
14 Correct 2 ms 4436 KB Output is correct
15 Correct 2 ms 4436 KB Output is correct
16 Correct 2 ms 4436 KB Output is correct
17 Correct 2 ms 4436 KB Output is correct
18 Correct 2 ms 4436 KB Output is correct
19 Correct 2 ms 4436 KB Output is correct
20 Correct 3 ms 4436 KB Output is correct
21 Correct 2 ms 4436 KB Output is correct
22 Correct 2 ms 4436 KB Output is correct
23 Correct 2 ms 4436 KB Output is correct
24 Correct 2 ms 4436 KB Output is correct
25 Correct 2 ms 4436 KB Output is correct
26 Correct 2 ms 4436 KB Output is correct
27 Correct 2 ms 4436 KB Output is correct
28 Correct 2 ms 4436 KB Output is correct
29 Correct 2 ms 4436 KB Output is correct
30 Correct 2 ms 4436 KB Output is correct
31 Correct 2 ms 4436 KB Output is correct
32 Correct 2 ms 4436 KB Output is correct
33 Correct 2 ms 4436 KB Output is correct
34 Correct 2 ms 4436 KB Output is correct
35 Correct 2 ms 4440 KB Output is correct
36 Correct 2 ms 4436 KB Output is correct
37 Correct 2 ms 4436 KB Output is correct
38 Correct 4 ms 4436 KB Output is correct
39 Correct 5 ms 4436 KB Output is correct
40 Correct 5 ms 4540 KB Output is correct
41 Correct 6 ms 4576 KB Output is correct
42 Correct 5 ms 4436 KB Output is correct
43 Correct 4 ms 4436 KB Output is correct
44 Correct 5 ms 4436 KB Output is correct
45 Correct 4 ms 4436 KB Output is correct
46 Correct 5 ms 4560 KB Output is correct
47 Correct 4 ms 4436 KB Output is correct
48 Correct 6 ms 4436 KB Output is correct
49 Correct 4 ms 4564 KB Output is correct
50 Correct 5 ms 4436 KB Output is correct
51 Correct 4 ms 4436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4436 KB Output is correct
2 Correct 2 ms 4436 KB Output is correct
3 Correct 2 ms 4436 KB Output is correct
4 Correct 3 ms 4436 KB Output is correct
5 Correct 2 ms 4436 KB Output is correct
6 Correct 2 ms 4436 KB Output is correct
7 Correct 2 ms 4436 KB Output is correct
8 Correct 2 ms 4436 KB Output is correct
9 Correct 2 ms 4436 KB Output is correct
10 Correct 2 ms 4436 KB Output is correct
11 Correct 2 ms 4436 KB Output is correct
12 Correct 2 ms 4436 KB Output is correct
13 Correct 2 ms 4436 KB Output is correct
14 Correct 2 ms 4436 KB Output is correct
15 Correct 2 ms 4436 KB Output is correct
16 Correct 2 ms 4436 KB Output is correct
17 Correct 2 ms 4436 KB Output is correct
18 Correct 2 ms 4436 KB Output is correct
19 Correct 2 ms 4436 KB Output is correct
20 Correct 3 ms 4436 KB Output is correct
21 Correct 2 ms 4436 KB Output is correct
22 Correct 2 ms 4436 KB Output is correct
23 Correct 2 ms 4436 KB Output is correct
24 Correct 2 ms 4436 KB Output is correct
25 Correct 2 ms 4436 KB Output is correct
26 Correct 2 ms 4436 KB Output is correct
27 Correct 2 ms 4436 KB Output is correct
28 Correct 2 ms 4436 KB Output is correct
29 Correct 2 ms 4436 KB Output is correct
30 Correct 2 ms 4436 KB Output is correct
31 Correct 2 ms 4436 KB Output is correct
32 Correct 2 ms 4436 KB Output is correct
33 Correct 2 ms 4436 KB Output is correct
34 Correct 2 ms 4436 KB Output is correct
35 Correct 2 ms 4440 KB Output is correct
36 Correct 2 ms 4436 KB Output is correct
37 Correct 2 ms 4436 KB Output is correct
38 Correct 4 ms 4436 KB Output is correct
39 Correct 5 ms 4436 KB Output is correct
40 Correct 5 ms 4540 KB Output is correct
41 Correct 6 ms 4576 KB Output is correct
42 Correct 5 ms 4436 KB Output is correct
43 Correct 4 ms 4436 KB Output is correct
44 Correct 5 ms 4436 KB Output is correct
45 Correct 4 ms 4436 KB Output is correct
46 Correct 5 ms 4560 KB Output is correct
47 Correct 4 ms 4436 KB Output is correct
48 Correct 6 ms 4436 KB Output is correct
49 Correct 4 ms 4564 KB Output is correct
50 Correct 5 ms 4436 KB Output is correct
51 Correct 4 ms 4436 KB Output is correct
52 Correct 282 ms 13020 KB Output is correct
53 Correct 299 ms 13036 KB Output is correct
54 Correct 245 ms 15952 KB Output is correct
55 Correct 240 ms 19368 KB Output is correct
56 Correct 244 ms 18608 KB Output is correct
57 Correct 263 ms 18384 KB Output is correct
58 Correct 273 ms 18748 KB Output is correct
59 Correct 249 ms 19248 KB Output is correct
60 Correct 236 ms 18632 KB Output is correct
61 Correct 246 ms 19408 KB Output is correct
62 Correct 245 ms 18708 KB Output is correct
63 Correct 207 ms 26680 KB Output is correct
64 Correct 249 ms 18888 KB Output is correct
65 Correct 276 ms 18880 KB Output is correct
66 Correct 271 ms 18796 KB Output is correct
67 Correct 275 ms 18764 KB Output is correct
68 Correct 295 ms 18780 KB Output is correct
69 Correct 307 ms 18508 KB Output is correct
70 Correct 277 ms 18532 KB Output is correct
71 Correct 276 ms 18472 KB Output is correct
72 Correct 282 ms 18600 KB Output is correct
73 Correct 277 ms 18628 KB Output is correct
74 Correct 273 ms 18584 KB Output is correct
75 Correct 294 ms 18652 KB Output is correct
76 Correct 276 ms 18668 KB Output is correct
77 Correct 257 ms 23496 KB Output is correct
78 Correct 274 ms 18664 KB Output is correct
79 Correct 281 ms 18120 KB Output is correct
80 Correct 264 ms 18120 KB Output is correct