Submission #884203

# Submission time Handle Problem Language Result Execution time Memory
884203 2023-12-06T18:10:50 Z DAleksa Long Distance Coach (JOI17_coach) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

#define int __int128;

struct Line {
    int a;
    int b;
    long long eval(int x) { return a * 1LL * x + b; }
};

const int N = 2e5 + 10;

long long X, T;
int n, m, W;
long long a[N];
long long b[N], B[N];
long long c[N], C[N];
int order[N];
long long pref[N];
long long dp[N];
long long ind[N];
long long cnt[N];
vector<Line> lines;
vector<long long> all;
map<long long, int> start_to_index;

long long get(int x) {
    long long ans = 1e18;
    for(Line l : lines) ans = min(ans, l.eval(x));
    return ans;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> X >> n >> m >> W >> T;
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= m; i++) cin >> B[i] >> C[i];
	for(int i = 1; i <= m; i++) order[i] = i;
	sort(order + 1, order + m + 1, [&](int i, int j) {
		return B[i] < B[j];
	});
	for(int i = 1; i <= m; i++) {
		b[i] = B[order[i]];
		c[i] = C[order[i]];
		all.push_back(b[i]);
		start_to_index[b[i]] = i;
		pref[i] = pref[i - 1] + c[i];
		cnt[i] = X / T + (b[i] <= X % T);
		ind[i] = -1;
	}
	sort(all.begin(), all.end());
	n++;
	a[n] = X;
//	for(int i : all) cout << i << " ";
//	cout << "\n";
	for(int i = n; i >= 1; i--) {
		int temp = a[i] % T;
		int index = lower_bound(all.begin(), all.end(), temp) - all.begin();
		index--;
		if(index == -1) continue;
		ind[start_to_index[(a[i] - (temp - all[index])) % T]] = a[i] - (temp - all[index]);
	}
//	for(int i = 1; i <= m; i++) cout << ind[i] << " ";
//	cout << "\n";
//    for(int i = 1; i <= m; i++) cout << cnt[i] << " ";
//    cout << "\n";
	for(int i = 1; i <= m; i++) {
		dp[i] = dp[i - 1] + W * cnt[i];
		if(ind[i] != -1) dp[i] = min(dp[i], get(W * (ind[i] / T)) + pref[i] + W * i * (ind[i] / T));
		lines.push_back({-i, dp[i] - pref[i]});
	}
//	for(int i = 1; i <= m; i++) cout << dp[i] << " ";
//	cout << "\n";
	cout << dp[m] + (X / T + 1) * W;
	return 0;
}

Compilation message

coach.cpp:5:13: error: declaration does not declare anything [-fpermissive]
    5 | #define int __int128;
      |             ^~~~~~~~
coach.cpp:8:5: note: in expansion of macro 'int'
    8 |     int a;
      |     ^~~
coach.cpp:8:9: error: 'a' does not name a type
    8 |     int a;
      |         ^
coach.cpp:5:13: error: declaration does not declare anything [-fpermissive]
    5 | #define int __int128;
      |             ^~~~~~~~
coach.cpp:9:5: note: in expansion of macro 'int'
    9 |     int b;
      |     ^~~
coach.cpp:9:9: error: 'b' does not name a type
    9 |     int b;
      |         ^
coach.cpp:5:21: error: expected ')' before ';' token
    5 | #define int __int128;
      |                     ^
coach.cpp:10:20: note: in expansion of macro 'int'
   10 |     long long eval(int x) { return a * 1LL * x + b; }
      |                    ^~~
coach.cpp:10:19: note: to match this '('
   10 |     long long eval(int x) { return a * 1LL * x + b; }
      |                   ^
coach.cpp:10:24: error: 'x' does not name a type
   10 |     long long eval(int x) { return a * 1LL * x + b; }
      |                        ^
coach.cpp:5:13: error: declaration does not declare anything [-fpermissive]
    5 | #define int __int128;
      |             ^~~~~~~~
coach.cpp:13:7: note: in expansion of macro 'int'
   13 | const int N = 2e5 + 10;
      |       ^~~
coach.cpp:13:11: error: 'N' does not name a type
   13 | const int N = 2e5 + 10;
      |           ^
coach.cpp:5:13: error: declaration does not declare anything [-fpermissive]
    5 | #define int __int128;
      |             ^~~~~~~~
coach.cpp:16:1: note: in expansion of macro 'int'
   16 | int n, m, W;
      | ^~~
coach.cpp:16:5: error: 'n' does not name a type
   16 | int n, m, W;
      |     ^
coach.cpp:17:13: error: 'N' was not declared in this scope
   17 | long long a[N];
      |             ^
coach.cpp:18:13: error: 'N' was not declared in this scope
   18 | long long b[N], B[N];
      |             ^
coach.cpp:18:19: error: 'N' was not declared in this scope
   18 | long long b[N], B[N];
      |                   ^
coach.cpp:19:13: error: 'N' was not declared in this scope
   19 | long long c[N], C[N];
      |             ^
coach.cpp:19:19: error: 'N' was not declared in this scope
   19 | long long c[N], C[N];
      |                   ^
coach.cpp:5:13: error: declaration does not declare anything [-fpermissive]
    5 | #define int __int128;
      |             ^~~~~~~~
coach.cpp:20:1: note: in expansion of macro 'int'
   20 | int order[N];
      | ^~~
coach.cpp:20:5: error: 'order' does not name a type
   20 | int order[N];
      |     ^~~~~
coach.cpp:21:16: error: 'N' was not declared in this scope
   21 | long long pref[N];
      |                ^
coach.cpp:22:14: error: 'N' was not declared in this scope
   22 | long long dp[N];
      |              ^
coach.cpp:23:15: error: 'N' was not declared in this scope
   23 | long long ind[N];
      |               ^
coach.cpp:24:15: error: 'N' was not declared in this scope
   24 | long long cnt[N];
      |               ^
coach.cpp:5:13: error: template argument 2 is invalid
    5 | #define int __int128;
      |             ^~~~~~~~
coach.cpp:27:16: note: in expansion of macro 'int'
   27 | map<long long, int> start_to_index;
      |                ^~~
coach.cpp:5:13: error: template argument 4 is invalid
    5 | #define int __int128;
      |             ^~~~~~~~
coach.cpp:27:16: note: in expansion of macro 'int'
   27 | map<long long, int> start_to_index;
      |                ^~~
coach.cpp:27:19: error: expected unqualified-id before '>' token
   27 | map<long long, int> start_to_index;
      |                   ^
coach.cpp:5:21: error: expected ')' before ';' token
    5 | #define int __int128;
      |                     ^
coach.cpp:29:15: note: in expansion of macro 'int'
   29 | long long get(int x) {
      |               ^~~
coach.cpp:29:14: note: to match this '('
   29 | long long get(int x) {
      |              ^
coach.cpp:29:19: error: 'x' does not name a type
   29 | long long get(int x) {
      |                   ^
coach.cpp: In function 'int main()':
coach.cpp:38:14: error: 'n' was not declared in this scope
   38 |  cin >> X >> n >> m >> W >> T;
      |              ^
coach.cpp:38:19: error: 'm' was not declared in this scope
   38 |  cin >> X >> n >> m >> W >> T;
      |                   ^
coach.cpp:38:24: error: 'W' was not declared in this scope
   38 |  cin >> X >> n >> m >> W >> T;
      |                        ^
coach.cpp:5:13: error: declaration does not declare anything [-fpermissive]
    5 | #define int __int128;
      |             ^~~~~~~~
coach.cpp:39:6: note: in expansion of macro 'int'
   39 |  for(int i = 1; i <= n; i++) cin >> a[i];
      |      ^~~
coach.cpp:39:10: error: 'i' was not declared in this scope
   39 |  for(int i = 1; i <= n; i++) cin >> a[i];
      |          ^
coach.cpp:39:23: error: expected ')' before ';' token
   39 |  for(int i = 1; i <= n; i++) cin >> a[i];
      |     ~                 ^
      |                       )
coach.cpp:39:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   39 |  for(int i = 1; i <= n; i++) cin >> a[i];
      |  ^~~
coach.cpp:39:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   39 |  for(int i = 1; i <= n; i++) cin >> a[i];
      |                         ^
coach.cpp:39:25: error: 'i' was not declared in this scope
coach.cpp:40:7: error: 'a' was not declared in this scope
   40 |  sort(a + 1, a + n + 1);
      |       ^
coach.cpp:5:13: error: declaration does not declare anything [-fpermissive]
    5 | #define int __int128;
      |             ^~~~~~~~
coach.cpp:41:6: note: in expansion of macro 'int'
   41 |  for(int i = 1; i <= m; i++) cin >> B[i] >> C[i];
      |      ^~~
coach.cpp:41:23: error: expected ')' before ';' token
   41 |  for(int i = 1; i <= m; i++) cin >> B[i] >> C[i];
      |     ~                 ^
      |                       )
coach.cpp:41:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   41 |  for(int i = 1; i <= m; i++) cin >> B[i] >> C[i];
      |  ^~~
coach.cpp:41:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   41 |  for(int i = 1; i <= m; i++) cin >> B[i] >> C[i];
      |                         ^
coach.cpp:5:13: error: declaration does not declare anything [-fpermissive]
    5 | #define int __int128;
      |             ^~~~~~~~
coach.cpp:42:6: note: in expansion of macro 'int'
   42 |  for(int i = 1; i <= m; i++) order[i] = i;
      |      ^~~
coach.cpp:42:23: error: expected ')' before ';' token
   42 |  for(int i = 1; i <= m; i++) order[i] = i;
      |     ~                 ^
      |                       )
coach.cpp:42:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   42 |  for(int i = 1; i <= m; i++) order[i] = i;
      |  ^~~
coach.cpp:42:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   42 |  for(int i = 1; i <= m; i++) order[i] = i;
      |                         ^
coach.cpp:43:7: error: 'order' was not declared in this scope
   43 |  sort(order + 1, order + m + 1, [&](int i, int j) {
      |       ^~~~~
coach.cpp:5:21: error: expected ')' before ';' token
    5 | #define int __int128;
      |                     ^
coach.cpp:43:37: note: in expansion of macro 'int'
   43 |  sort(order + 1, order + m + 1, [&](int i, int j) {
      |                                     ^~~
coach.cpp:43:36: note: to match this '('
   43 |  sort(order + 1, order + m + 1, [&](int i, int j) {
      |                                    ^
coach.cpp: In lambda function:
coach.cpp:5:21: error: expected '{' before ';' token
    5 | #define int __int128;
      |                     ^
coach.cpp:43:37: note: in expansion of macro 'int'
   43 |  sort(order + 1, order + m + 1, [&](int i, int j) {
      |                                     ^~~
coach.cpp: In function 'int main()':
coach.cpp:5:21: error: expected ')' before ';' token
    5 | #define int __int128;
      |                     ^
coach.cpp:43:37: note: in expansion of macro 'int'
   43 |  sort(order + 1, order + m + 1, [&](int i, int j) {
      |                                     ^~~
coach.cpp:43:6: note: to match this '('
   43 |  sort(order + 1, order + m + 1, [&](int i, int j) {
      |      ^
coach.cpp:5:13: error: expected primary-expression before '__int128'
    5 | #define int __int128;
      |             ^~~~~~~~
coach.cpp:43:44: note: in expansion of macro 'int'
   43 |  sort(order + 1, order + m + 1, [&](int i, int j) {
      |                                            ^~~
coach.cpp:43:48: error: 'j' was not declared in this scope
   43 |  sort(order + 1, order + m + 1, [&](int i, int j) {
      |                                                ^
coach.cpp:45:3: error: expected primary-expression before ')' token
   45 |  });
      |   ^
coach.cpp:5:13: error: declaration does not declare anything [-fpermissive]
    5 | #define int __int128;
      |             ^~~~~~~~
coach.cpp:46:6: note: in expansion of macro 'int'
   46 |  for(int i = 1; i <= m; i++) {
      |      ^~~
coach.cpp:46:23: error: expected ')' before ';' token
   46 |  for(int i = 1; i <= m; i++) {
      |     ~                 ^
      |                       )
coach.cpp:46:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   46 |  for(int i = 1; i <= m; i++) {
      |  ^~~
coach.cpp:46:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   46 |  for(int i = 1; i <= m; i++) {
      |                         ^
coach.cpp:5:13: error: declaration does not declare anything [-fpermissive]
    5 | #define int __int128;
      |             ^~~~~~~~
coach.cpp:60:6: note: in expansion of macro 'int'
   60 |  for(int i = n; i >= 1; i--) {
      |      ^~~
coach.cpp:60:23: error: expected ')' before ';' token
   60 |  for(int i = n; i >= 1; i--) {
      |     ~                 ^
      |                       )
coach.cpp:60:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   60 |  for(int i = n; i >= 1; i--) {
      |  ^~~
coach.cpp:60:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   60 |  for(int i = n; i >= 1; i--) {
      |                         ^
coach.cpp:5:13: error: declaration does not declare anything [-fpermissive]
    5 | #define int __int128;
      |             ^~~~~~~~
coach.cpp:71:6: note: in expansion of macro 'int'
   71 |  for(int i = 1; i <= m; i++) {
      |      ^~~
coach.cpp:71:23: error: expected ')' before ';' token
   71 |  for(int i = 1; i <= m; i++) {
      |     ~                 ^
      |                       )
coach.cpp:71:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   71 |  for(int i = 1; i <= m; i++) {
      |  ^~~
coach.cpp:71:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   71 |  for(int i = 1; i <= m; i++) {
      |                         ^
coach.cpp:78:10: error: 'dp' was not declared in this scope
   78 |  cout << dp[m] + (X / T + 1) * W;
      |          ^~