Submission #431642

# Submission time Handle Problem Language Result Execution time Memory
431642 2021-06-17T13:58:10 Z jamezzz Long Distance Coach (JOI17_coach) C++17
16 / 100
1 ms 460 KB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#include <ext/rope>
using namespace __gnu_cxx;

typedef tree<long long, null_type, less<long long>,
rb_tree_tag, tree_order_statistics_node_update> pbds;
//less_equal for identical elements

#define DEBUG

#ifdef DEBUG
#define debug(...) printf(__VA_ARGS__);
#else
#define debug(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
mt19937 rng(time(0));

ll x,n,m,w,t,s[10],d,c,memo[12][515],memo2[12][515];
vll v;

//cost to travel to pos+1 if u r at pos, with this mask of people
ll calc(int pos,int msk){
	if(memo2[pos][msk]!=-1)return memo2[pos][msk];
	ll res=0;
	for(int i=0;i<=m;++i){
		if(msk&(1<<i)){
			if(v[i].fi>s[pos+1])continue; //start after next pos
			ll l,r;
			if(s[pos]%t<=v[i].fi%t)l=s[pos]+v[i].fi%t-s[pos]%t;
			else l=s[pos]+v[i].fi%t+t-s[pos]%t;
			if(v[i].fi%t<=s[pos+1]%t)r=s[pos+1]-(s[pos+1]%t-v[i].fi%t);
			else r=s[pos+1]-(s[pos+1]%t+t-v[i].fi%t);
			l=max(l,v[i].fi);	
			if(r<l||s[pos+1]<l||r<s[pos])continue;
			res+=((r-l)/t+1)*w;
		}
	}
	return memo2[pos][msk]=res;
}

//check if i is between pos and pos+1
bool between(int pos,int i){
	ll l;
	if(s[pos]%t<=v[i].fi%t)l=s[pos]+v[i].fi%t-s[pos]%t;
	else l=s[pos]+v[i].fi%t+t-s[pos]%t;
	l=max(l,v[i].fi);
	if(l>s[pos+1])return false;
	return true;
}

//minimum cost if u r at pos, with this mask of people
ll dp(int pos,int msk){
	int tmsk=msk;
	if(memo[pos][msk]!=-1)return memo[pos][msk];
	if(pos==n+1)return 0;
	ll cost=calc(pos,msk),res=dp(pos+1,msk)+cost;
	for(int i=m;i>=1;--i){
		if((msk&(1<<i))==0)continue;
		if(s[pos+1]%t<v[i].fi%t)continue;
		if(s[pos+1]<v[i].fi)continue;
		if(!between(pos,i))continue;
		msk^=(1<<i);
		cost+=v[i].se-w;
		res=min(res,dp(pos+1,msk)+cost);
	}
	return memo[pos][tmsk]=res;
}

bool cmp(pll &a,pll &b){
	if(a.fi%t==b.fi%t)return a.fi<b.fi;
	return a.fi%t<b.fi%t;
}

int main(){
	sf("%lld%lld%lld%lld%lld",&x,&n,&m,&w,&t);
	assert(n<=8&&m<=8);
	for(int i=1;i<=n;++i)sf("%lld",&s[i]);
	sort(s+1,s+n+1);
	s[n+1]=x;
	for(int i=0;i<m;++i){
		sf("%lld%lld",&d,&c);
		v.pb(d,c);
	}
	v.pb(0,-1);
	sort(all(v),cmp);
	memset(memo,-1,sizeof memo);
	memset(memo2,-1,sizeof memo2);
	pf("%lld\n",dp(0,(1<<(m+1))-1));
}

Compilation message

coach.cpp: In function 'int main()':
coach.cpp:99:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |  sf("%lld%lld%lld%lld%lld",&x,&n,&m,&w,&t);
      |    ^
coach.cpp:101:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |  for(int i=1;i<=n;++i)sf("%lld",&s[i]);
      |                         ^
coach.cpp:105:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |   sf("%lld%lld",&d,&c);
      |     ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 368 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 368 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Runtime error 1 ms 460 KB Execution killed with signal 6
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 368 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Runtime error 1 ms 460 KB Execution killed with signal 6
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 368 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Runtime error 1 ms 460 KB Execution killed with signal 6
24 Halted 0 ms 0 KB -