제출 #1159840

#제출 시각아이디문제언어결과실행 시간메모리
1159840HakunaSemiexpress (JOI17_semiexpress)C++20
0 / 100
468 ms24476 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; long long n, m, k, a, b, c, t; vector<bool> used(N); vector< pair<int, int> > g[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> k >> a >> b >> c >> t; for (int i = 1; i < n; i++) { g[i].push_back({i + 1, a}); } int s[m + 1]; for (int i = 1; i <= m; i++) { cin >> s[i]; for (int j = 1; j < i; j++) { int dif = s[i] - s[j]; g[s[j]].push_back({s[i], dif * b}); g[s[j]].push_back({s[i], dif * c}); } used[s[i]] = 1; } k -= m; if (k == 0) { vector<long long> d(n + 1, 1e18); d[1] = 0; set< pair<long long, int> > q; q.emplace(0, 1); while (!q.empty()) { auto [mn, v] = *q.begin(); q.erase(q.begin()); for (auto [to, w] : g[v]) { if (d[to] > mn + w) { q.erase({d[to], to}); d[to] = mn + w; q.emplace(d[to], to); } } } int ans = 0; for (int i = 2; i <= n; i++) { if (d[i] <= t) ans++; } cout << ans; } else if (k == 1) { int ans = 0; for (int i = 1; i <= n; i++) { if (used[i]) continue; used[i] = 1; for (int j = 1; j <= n; j++) { if (i == j || !used[j]) continue; if (j < i) g[j].push_back({i, c * (i - j)}); if (j > i) g[i].push_back({j, c * (j - i)}); } vector<long long> d(n + 1, 1e18); d[1] = 0; set< pair<long long, int> > q; q.emplace(0, 1); while (!q.empty()) { auto [mn, v] = *q.begin(); q.erase(q.begin()); for (auto [to, w] : g[v]) { if (d[to] > mn + w) { q.erase({d[to], to}); d[to] = mn + w; q.emplace(d[to], to); } } } int res = 0; for (int x = 2; x <= n; x++) { if (d[x] <= t) res++; } ans = max(ans, res); for (int j = 1; j <= n; j++) { if (i == j || !used[j]) continue; if (j < i) g[j].pop_back(); if (j > i) g[i].pop_back(); } used[i] = 0; } cout << ans; } else if (k == 2) { int ans = 0; for (int i = 1; i <= n; i++) { if (used[i]) continue; used[i] = 1; for (int j = 1; j <= n; j++) { if (i == j || !used[j]) continue; if (j < i) g[j].push_back({i, c * (i - j)}); if (j > i) g[i].push_back({j, c * (j - i)}); } for (int j = i + 1; j <= n; j++) { if (used[j]) continue; used[j] = 1; for (int x = 1; x <= n; x++) { if (j == x || !used[x]) continue; if (j < x) g[j].push_back({x, c * (x - j)}); if (j > x) g[x].push_back({j, c * (j - x)}); } vector<long long> d(n + 1, 1e18); d[1] = 0; set< pair<long long, int> > q; q.emplace(0, 1); while (!q.empty()) { auto [mn, v] = *q.begin(); q.erase(q.begin()); for (auto [to, w] : g[v]) { if (d[to] > mn + w) { q.erase({d[to], to}); d[to] = mn + w; q.emplace(d[to], to); } } } int res = 0; for (int x = 2; x <= n; x++) { if (d[x] <= t) res++; } ans = max(ans, res); used[j] = 0; for (int x = 1; x <= n; x++) { if (j == x || !used[x]) continue; if (j < x) g[j].pop_back(); if (j > x) g[x].pop_back(); } cout << i << ' ' << j << ' ' << res << '\n'; } used[i] = 0; for (int j = 1; j <= n; j++) { if (i == j || !used[j]) continue; if (j < i) g[j].pop_back(); if (j > i) g[i].pop_back(); } } cout << ans; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...