This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#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;
int calc(vector<int> s) {
int ans = 0;
int last = 0;
int base_time = 0;
for (int i = 0; i < s.size(); i++) {
if (i != 0 && semiexpress.count(s[i])) {
base_time = (last - 1) * B + (s[i] - last) * C;
} else {
last = s[i];
base_time = (s[i] - 1) * B;
}
if (base_time <= T) ans++;
int cnt = max(0ll, ((T - base_time) / A));
//cout << s[i] + cnt << " " << n << "\n";
if (s[i] + cnt > n || (i + 1 < s.size() && s[i] + cnt >= s[i + 1]) ) {
if (s[i] + cnt > n) cnt = n - s[i];
if (i + 1 < s.size() && s[i] + cnt >= s[i + 1]) {
cnt = s[i + 1] - s[i] - 1;
}
}
ans += cnt;
}
return ans;
}
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 get_cnt(int base_time, int l, int r) {
int cnt = (T - base_time) / A;
if (l + cnt >= r) {
cnt = r - l - 1;
}
cnt = max(cnt, 0ll);
if (base_time <= T) cnt++;
return cnt;
}
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);
if (active.size() > 5 * k) break;
}
set<int> r;
for (auto x: s) r.insert(x);
for (auto x: active) {
if (!r.count(x.S)) {
r.insert(x.S);
semiexpress.insert(x.S);
}
if (r.size() >= k) break;
}
//assert(r.size() <= k);
s.clear();
for (auto x: r) s.pb(x);
sort(all(s));
//assert(s.size() <= k);
int ans = 0;
int base_time = 0;
int last = 0;
for (int i = 0; i < s.size(); i++) {
if (semiexpress.count(s[i])) {
base_time = (s[i] - last) * C + (last - 1) * B;
} else {
last = s[i];
base_time = (last - 1) * B;
}
if (i < s.size() - 1) ans += get_cnt(base_time, s[i], s[i + 1]);
else ans += get_cnt(base_time, s[i], n);
}
cout << ans - 1 << "\n";
}
Compilation message (stderr)
semiexpress.cpp: In function 'long long int calc(std::vector<long long int>)':
semiexpress.cpp:65:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < s.size(); i++) {
~~^~~~~~~~~~
semiexpress.cpp:75:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (s[i] + cnt > n || (i + 1 < s.size() && s[i] + cnt >= s[i + 1]) ) {
~~~~~~^~~~~~~~~~
semiexpress.cpp:77:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (i + 1 < s.size() && s[i] + cnt >= s[i + 1]) {
~~~~~~^~~~~~~~~~
semiexpress.cpp: In function 'void try_add(long long int, long long int, long long int)':
semiexpress.cpp:87:50: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (l == r || base_time > T || active.size() > 5 * k) return;
~~~~~~~~~~~~~~^~~~~~~
semiexpress.cpp: In function 'int main()':
semiexpress.cpp:134:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (active.size() > 5 * k) break;
~~~~~~~~~~~~~~^~~~~~~
semiexpress.cpp:143:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (r.size() >= k) break;
~~~~~~~~~^~~~
semiexpress.cpp:155:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < s.size(); i++) {
~~^~~~~~~~~~
semiexpress.cpp:162:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (i < s.size() - 1) ans += get_cnt(base_time, s[i], s[i + 1]);
~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |