Submission #1235793

#TimeUsernameProblemLanguageResultExecution timeMemory
1235793M_SH_OSemiexpress (JOI17_semiexpress)C++20
48 / 100
59 ms122692 KiB
/*#pragma GCC optimize("O3") #pragma GCC optimization("Ofast,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")*/ #include <bits/stdc++.h> /*#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp>*/ #define ll long long #define ll1 long long #define ull unsigned long long #define dou long double #define str string #define vll vector<ll> #define vi vector<int> #define pll pair<ll, ll> #define vpll vector<pll> #define vbool vector<bool> #define vstr vector<str> #define vvll vector<vll> #define pb push_back #define pf push_front #define endl "\n" #define fr first #define se second // #define sortcmp(a) sort(a.begin(), a.end(), cmp) #define sort(a) sort(a.begin(), a.end()) #define reverse(a) reverse(a.begin(), a.end()) #define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define INF 1000000000000000000 #define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> using namespace std; //using namespace __gnu_pbds; mt19937 rng(time(0)); ll randll(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rng); } int main(){ speed; srand(time(0)); ll n, m, k; cin >> n >> m >> k; ll a, b, c; cin >> a >> b >> c; ll d; cin >> d; vll v(m); vbool us(n+7, 0); for (int i =0 ; i < m; i ++) { cin >> v[i]; us[v[i]] = 1; } vll dp(n+7, INF); dp[1] = 0; ll pos = -1; ll res = 0; for (int i = 1; i <= n; i ++) { dp[i] = min(dp[i], dp[i-1]+a); if (pos != -1 && us[i]) { dp[i] = min(dp[i], dp[pos]+(i-pos)*b); } if (us[i]) pos = i; if (dp[i] <= d && i > 1) res ++; } //cout << res << endl; for (; k > m; k --) { ll maxl = 0, x = -1, p; pos = 1; for (int i = 2; i <= n; i ++) { if (dp[i] > d && dp[i-1] <= d && !us[i]) { ll k = 0; ll dist = dp[pos]+(i-pos)*c; if (dist > d) continue; for (int j = i; j <= n; j ++) { if (us[j]) break; if (dist <= d) k ++; else break; dist += a; } if (k > maxl) { maxl = k; x = i; p = pos; } } if (us[i]) pos = i; } //cout << x << endl; if (x == -1) break; ll dist = dp[p]+(x-p)*c; for (int j = x; j <= n; j ++) { if (us[j]) break; if (dist <= d) dp[j] = dist; else break; dist += a; } us[x] = 1; } res = 0; for (int i = 2; i <= n; i ++) { if (dp[i] <= d) res ++; } cout << res << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...