답안 #431603

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
431603 2021-06-17T13:29:48 Z maomao90 Long Distance Coach (JOI17_coach) C++17
컴파일 오류
0 ms 0 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 10

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:108:1: error: unterminated comment
  108 | /*
      | ^
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);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~