Submission #431608

# Submission time Handle Problem Language Result Execution time Memory
431608 2021-06-17T13:33:09 Z maomao90 Long Distance Coach (JOI17_coach) C++17
16 / 100
2000 ms 312 KB
#include <bits/stdc++.h> 
using namespace std;

template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb emplace_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

#ifdef DEBUG
#define debug(args...) _debug(args)
void _debug(const char* format, ...) {
		va_list args;
			va_start(args, format);
				vprintf(format, args);
					va_end(args);
}
#else
#define debug(args...)
#endif

#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 200005

ll x, t;
int n, m, w;
ll s[MAXN];
pll dc[MAXN];

ll cnt[MAXN];
ll dp(int ri, int msk) {
	if (ri == n) return 0;
	vii v;
	ll mn = s[ri] / t * t;
	REP (i, 0, m) {
		if (!(msk & (1 << i))) continue;
		ll cur = (s[ri] - dc[i].FI) / t * t + dc[i].FI;
		if (s[ri] - dc[i].FI < 0) cur = dc[i].FI - t;
		if (cur > mn) {
			v.pb(cur, i);
		}
	}
	ll prv = ri == 0 ? 0 : s[ri - 1];
	ll k1 = s[ri] / t, k2 = (prv - 1) / t + 1;
	if (prv - 1 < 0) k2 = 0;
	//debug(" %d %s: %d %lld %lld\n", ri, bitset<4>(msk).to_string().c_str(), -1, k1, k2);
	ll sum = (ll) (k1 - k2 + 1) * w;
	REP (i, 0, m) {
		ll k1 = (s[ri] - dc[i].FI) / t, k2 = (prv - dc[i].FI - 1) / t + 1;
		if (prv - dc[i].FI - 1 < 0) k2 = 0;
		if (s[ri] - dc[i].FI < 0) k1 = -1;
		//debug(" %d %s: %d %lld %lld\n", ri, bitset<4>(msk).to_string().c_str(), i, k1, k2);
		cnt[i] = k1 - k2 + 1;
		if (msk & (1 << i)) {
			sum += (ll) cnt[i] * w;
			//debug(" %d %s: %lld %d %d %lld\n", ri, bitset<4>(msk).to_string().c_str(), i, cnt[i], w, sum);
		}
	}
	sort(ALL(v), greater<ii>());
	int tmsk = msk;
	ll res = dp(ri + 1, msk) + sum;
	debug(" %d %s: %lld\n", ri, bitset<4>(msk).to_string().c_str(), sum);
	REP (_, 0, v.size()) {
		sum -= w;
		auto [_a, i] = v[_];
		tmsk ^= (1 << i);
		sum += dc[i].SE;
		debug(" %d %s: %lld\n", ri, bitset<4>(msk).to_string().c_str(), sum);
		mnto(res, dp(ri + 1, tmsk) + sum);
	}
	debug("%d %s: %lld\n", ri, bitset<4>(msk).to_string().c_str(), res);
	return res;
}

int main() {
	scanf("%lld%d%d%d%lld", &x, &n, &m, &w, &t);
	REP (i, 0, n) {
		scanf("%lld", &s[i]);
	}
	sort(s, s + n);
	s[n] = x;
	n++;
	REP (i, 0, m) {
		scanf("%lld%lld", &dc[i].FI, &dc[i].SE);
	}
	sort(dc, dc + m);
	printf("%lld\n", dp(0, (1 << m) - 1));
	return 0;
}

/*
19 1 4 8 7
5
1 20
2 10
4 5
6 5

105 3 5 9 10
59
68
71
4 71     
6 32
7 29
3 62
2 35

1000000000000 1 1 1000000 6
999999259244
1 123456789
*/

Compilation message

coach.cpp: In function 'll dp(int, int)':
coach.cpp:8:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define REP(i, s, e) for (int i = s; i < e; i++)
......
   80 |  REP (_, 0, v.size()) {
      |       ~~~~~~~~~~~~~~                    
coach.cpp:80:2: note: in expansion of macro 'REP'
   80 |  REP (_, 0, v.size()) {
      |  ^~~
coach.cpp: In function 'int main()':
coach.cpp:93:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |  scanf("%lld%d%d%d%lld", &x, &n, &m, &w, &t);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.cpp:95:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |   scanf("%lld", &s[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
coach.cpp:101:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |   scanf("%lld%lld", &dc[i].FI, &dc[i].SE);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 204 KB Output is correct
5 Correct 2 ms 204 KB Output is correct
6 Correct 2 ms 204 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 2 ms 204 KB Output is correct
14 Correct 4 ms 312 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 2 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 204 KB Output is correct
5 Correct 2 ms 204 KB Output is correct
6 Correct 2 ms 204 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 2 ms 204 KB Output is correct
14 Correct 4 ms 312 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 2 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Execution timed out 2028 ms 204 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 204 KB Output is correct
5 Correct 2 ms 204 KB Output is correct
6 Correct 2 ms 204 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 2 ms 204 KB Output is correct
14 Correct 4 ms 312 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 2 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Execution timed out 2028 ms 204 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 204 KB Output is correct
5 Correct 2 ms 204 KB Output is correct
6 Correct 2 ms 204 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 2 ms 204 KB Output is correct
14 Correct 4 ms 312 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 2 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Execution timed out 2028 ms 204 KB Time limit exceeded
24 Halted 0 ms 0 KB -