# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
998769 |
2024-06-14T16:36:26 Z |
NoLove |
Džumbus (COCI19_dzumbus) |
C++14 |
|
31 ms |
5712 KB |
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << #x << " = " << x << endl
#define _ << " _ " <<
typedef long long ll;
typedef long double ld;
const int MAXN = 1010, MAXQ = 2e5 + 10;
const ll INF = 1e15;
int n, m, q;
ll c[MAXN];
vector<int> e[MAXN];
ll dp[MAXN][2][2];
pair<int, int> query[MAXQ];
int ans[MAXQ];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> c[i];
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--; b--;
e[a].push_back(b);
e[b].push_back(a);
}
int x = -1, prev_x = -1;
for (int i = 0; i < n; i++)
if (e[i].size() == 1) {
prev_x = i;
x = e[i][0];
break;
}
for (int i = 0; i <= n; i++)
dp[i][0][0] = dp[i][1][0] = INF;
dp[0][0][0] = 0;
while (true) {
for (int i = 0; i <= n; i++) {
dp[i][0][1] = min(dp[i][0][0], dp[i][1][0]);
dp[i][1][1] = INF;
if (i >= 1) dp[i][1][1] = min(dp[i][1][1],
dp[i - 1][1][0] + c[x]);
if (i >= 2) dp[i][1][1] = min(dp[i][1][1],
dp[i - 2][0][0] + c[x] + c[prev_x]);
}
for (int i = 0; i <= n; i++) {
dp[i][0][0] = dp[i][0][1];
dp[i][1][0] = dp[i][1][1];
}
if (e[x].size() == 1) break;
int tmp = e[x][0] + e[x][1] - prev_x;
prev_x = x;
x = tmp;
}
for (int i = n; i >= 0; i--) {
dp[i][0][0] = min(dp[i][0][0], dp[i][1][0]);
if (i < n) dp[i][0][0] = min(dp[i][0][0], dp[i + 1][0][0]);
}
cin >> q;
for (int i = 0; i < q; i++) {
cin >> query[i].first;
query[i].second = i;
}
sort(query, query + q);
int answer = 0;
for (int i = 0; i < q; i++) {
while (answer < n && dp[answer + 1][0][0] <= query[i].first)
answer++;
ans[query[i].second] = answer;
}
for (int i = 0; i < q; i++)
cout << ans[i] << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2396 KB |
Output is correct |
2 |
Correct |
3 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2396 KB |
Output is correct |
2 |
Correct |
3 ms |
2396 KB |
Output is correct |
3 |
Correct |
25 ms |
4848 KB |
Output is correct |
4 |
Correct |
31 ms |
5712 KB |
Output is correct |
5 |
Correct |
26 ms |
5072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
4432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2396 KB |
Output is correct |
2 |
Correct |
3 ms |
2396 KB |
Output is correct |
3 |
Correct |
25 ms |
4848 KB |
Output is correct |
4 |
Correct |
31 ms |
5712 KB |
Output is correct |
5 |
Correct |
26 ms |
5072 KB |
Output is correct |
6 |
Incorrect |
21 ms |
4432 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |