//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("unroll-all-loops")
#include <bits/stdc++.h>
//#define TASK "lca"
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define pb push_back
#define int long long
#define pii pair<int, int>
typedef long long ll;
//typedef long double ld;
using namespace std;
const int INF = 1e18;
const int MAXN = 1e8;
const int MOD = 1e9 + 7;
const double EPS = 1e-12;
const vector<int> dx = {1, 0, -1, 0, 0, 1, 0, -1};
//char buf[(int)1e9];
//size_t p_ = 0;
//
//inline void *operator new(size_t n_) {
// p_ += n_;
// return buf + p_ - n_;
//}
//inline void operator delete(void*) {};
ll power(ll x, ll n, ll mod = 1e9 + 7) {
if (n == 0) return 1ll;
if (n & 1ll) return power(x, n - 1ll, mod) * x % mod;
ll tmp = power(x, n >> 1ll, mod);
return (tmp * tmp) % mod;
}
ll gcd(ll a, ll b) {
if (b == 0) return a;
return gcd (b, a % b);
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
set<int> semiexpress;
set<pii, greater<pii>> active;
int A, B, C, T;
int n, m, k;
void try_add(int base_time, int l, int r) {
if (l >= r || base_time > T || active.size() > 5 * k) return;
int cnt = (T - base_time) / A;
if (l + cnt >= r) {
cnt = r - l - 1;
}
active.insert({cnt, l});
base_time += (cnt + 1) * C;
try_add(base_time, l + cnt + 1, r);
}
int solve(vector<int> s) {
assert(s.size() <= k && s.size() >= m);
int ans = 0;
s.pb(n + 1);
int cur_time = 0;
int last_express_station = 0;
for (int i = 0; i < s.size() - 1; i++) {
if (semiexpress.count(s[i])) {
cur_time = (last_express_station - 1) * B + (s[i] - last_express_station) * C;
} else {
last_express_station = s[i];
cur_time = (last_express_station - 1) * B;
}
if (cur_time > T) continue;
int cnt = (T - cur_time) / A;
assert(cnt >= 0);
if (s[i] + cnt >= s[i + 1]) {
cnt = s[i + 1] - s[i] - 1;
}
assert(cnt >= 0);
ans += cnt + 1;
}
return ans - 1;
}
signed main() {
#ifndef LOCAL
#ifdef TASK
freopen(TASK".in", "r", stdin);
freopen(TASK".out", "w", stdout);
#endif
#endif
#ifdef LOCAL
//freopen("/Users/alekseygolub/Desktop/с++/ABS/ABS/input.txt", "r", stdin);
#endif
iostream::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
srand(924653523);
// == SOLUTION == //
cin >> n >> m >> k;
cin >> A >> B >> C >> T;
T++;
vector<int> s(m);
for (auto &in: s) cin >> in;
for (int i = 0; i < m; i++) {
int base_time = (s[i] - 1) * B;
if (i < m - 1)
try_add(base_time, s[i], s[i + 1]);
else
try_add(base_time, s[i], n + 1);
if (active.size() > 5 * k) break;
}
set<int> cur_station;
for (auto x: s) cur_station.insert(x);
for (auto x: active) {
if (!cur_station.count(x.S)) {
semiexpress.insert(x.S);
}
cur_station.insert(x.S);
if (cur_station.size() == k) break;
}
cout << solve(vector<int>(all(cur_station))) << "\n";
}
Compilation message
semiexpress.cpp: In function 'void try_add(long long int, long long int, long long int)':
semiexpress.cpp:62:50: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (l >= r || base_time > T || active.size() > 5 * k) return;
~~~~~~~~~~~~~~^~~~~~~
In file included from /usr/include/c++/7/cassert:44:0,
from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
from semiexpress.cpp:6:
semiexpress.cpp: In function 'long long int solve(std::vector<long long int>)':
semiexpress.cpp:73:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
assert(s.size() <= k && s.size() >= m);
~~~~~~~~~^~~~
semiexpress.cpp:73:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
assert(s.size() <= k && s.size() >= m);
~~~~~~~~~^~~~
semiexpress.cpp:78:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < s.size() - 1; i++) {
~~^~~~~~~~~~~~~~
semiexpress.cpp: In function 'int main()':
semiexpress.cpp:123:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (active.size() > 5 * k) break;
~~~~~~~~~~~~~~^~~~~~~
semiexpress.cpp:132:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (cur_station.size() == k) break;
~~~~~~~~~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
360 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
580 KB |
Output is correct |
6 |
Correct |
2 ms |
612 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
2 ms |
636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
360 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
580 KB |
Output is correct |
6 |
Correct |
2 ms |
612 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
2 ms |
636 KB |
Output is correct |
9 |
Correct |
2 ms |
636 KB |
Output is correct |
10 |
Correct |
2 ms |
636 KB |
Output is correct |
11 |
Correct |
2 ms |
636 KB |
Output is correct |
12 |
Correct |
2 ms |
636 KB |
Output is correct |
13 |
Correct |
2 ms |
636 KB |
Output is correct |
14 |
Correct |
2 ms |
752 KB |
Output is correct |
15 |
Correct |
2 ms |
752 KB |
Output is correct |
16 |
Correct |
2 ms |
752 KB |
Output is correct |
17 |
Correct |
2 ms |
752 KB |
Output is correct |
18 |
Correct |
2 ms |
752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
360 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
580 KB |
Output is correct |
6 |
Correct |
2 ms |
612 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
2 ms |
636 KB |
Output is correct |
9 |
Correct |
2 ms |
636 KB |
Output is correct |
10 |
Correct |
2 ms |
636 KB |
Output is correct |
11 |
Correct |
2 ms |
636 KB |
Output is correct |
12 |
Correct |
2 ms |
636 KB |
Output is correct |
13 |
Correct |
2 ms |
636 KB |
Output is correct |
14 |
Correct |
2 ms |
752 KB |
Output is correct |
15 |
Correct |
2 ms |
752 KB |
Output is correct |
16 |
Correct |
2 ms |
752 KB |
Output is correct |
17 |
Correct |
2 ms |
752 KB |
Output is correct |
18 |
Correct |
2 ms |
752 KB |
Output is correct |
19 |
Correct |
2 ms |
764 KB |
Output is correct |
20 |
Correct |
3 ms |
764 KB |
Output is correct |
21 |
Correct |
4 ms |
1532 KB |
Output is correct |
22 |
Correct |
5 ms |
1532 KB |
Output is correct |
23 |
Correct |
7 ms |
2428 KB |
Output is correct |
24 |
Correct |
5 ms |
2428 KB |
Output is correct |
25 |
Correct |
2 ms |
2428 KB |
Output is correct |
26 |
Correct |
3 ms |
2428 KB |
Output is correct |
27 |
Correct |
4 ms |
2428 KB |
Output is correct |
28 |
Correct |
5 ms |
2428 KB |
Output is correct |
29 |
Incorrect |
4 ms |
2428 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |