# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
940919 | 2024-03-08T02:12:56 Z | beaboss | Wiring (IOI17_wiring) | C++14 | 33 ms | 14156 KB |
// Source: https://oj.uz/problem/view/IOI17_wiring // #include "wiring.h" #include "bits/stdc++.h" using namespace std; #define s second #define f first #define pb push_back typedef long long ll; typedef pair<ll, ll> pii; typedef vector<pii> vpii; typedef vector<ll> vi; #define FOR(i, a, b) for (ll i = (a); i<b; i++) bool ckmin(ll& a, ll b){ return b < a ? a = b, true : false; } bool ckmax(ll& a, ll b){ return b > a ? a = b, true : false; } const ll INF = 1e18; ll min_total_length(vector<int> x, vector<int> y) { vi r; vi b; vector<vi> dp; vector<vi> pref; ll n = x.size(), m = y.size(); FOR(i, 0 ,n) r.pb(x[i]); FOR(i, 0, m) b.pb(y[i]); ll i, j; i = j = 0; r.pb(INF); b.pb(INF); while (i != n || j != m) { // cout << i << j << endl; ll sz = 0; ll here=pref.size(); pref.pb({0}); if (r[i] < b[j]) { while (i != n && r[i] < b[j]) { pref[here].pb(r[i]); sz++;i++; } } else { while (j != m && b[j] < r[i]) { pref[here].pb(b[j]); sz++;j++; } } dp.pb(vi(sz+1, INF)); assert(pref[here].size() == sz+1); FOR(i, 1, sz+1) pref[here][i] += pref[here][i-1]; } dp[0][0] = 0; FOR(i, 1, dp.size()) { // cout << i << endl; ll best = INF; FOR(j, 0, dp[i].size()) { if ((ll) dp[i-1].size() - j - 1 >= 0) { // cout << 'd' << endl; // cout << best << endl; best = min(best, dp[i-1][dp[i-1].size() - j-1] - (pref[i-1][dp[i-1].size()-1] - pref[i-1][dp[i-1].size() - j-1])); // cout << best << endl; // cout << dp[i-1].size() - j-1 << endl; } // cout << i << j << ' ' << best << pref[i][j] << endl; ckmin(dp[i][j], best + pref[i][j]); best -= pref[i-1][pref[i-1].size() - 1] - pref[i-1][pref[i-1].size() - 2]; // get the last element from before // cout << ' ' << dp[i][j] << endl; } best = INF; for (ll j = dp[i-1].size() - 1; j >= 0; j--) { best = min(best, dp[i-1][dp[i-1].size() - j - 1] - (pref[i-1][dp[i-1].size()-1] - pref[i-1][dp[i-1].size() - j - 1])); // cout << best << endl; if (j < dp[i].size()) ckmin(dp[i][j], best + pref[i][j]); best += pref[i][1]; // cout << i << j << ' ' << dp[i][j] << endl; } } return dp[dp.size()-1][dp[dp.size()-1].size()-1]; } // int main() { // ios::sync_with_stdio(false); // cin.tie(nullptr); // ll res = min_total_length({0, 1, 2, 3}, {5, 6}); // cout << res << endl; // }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 344 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 16 ms | 6892 KB | Output is correct |
4 | Correct | 16 ms | 6768 KB | Output is correct |
5 | Correct | 16 ms | 6676 KB | Output is correct |
6 | Correct | 22 ms | 8792 KB | Output is correct |
7 | Correct | 22 ms | 8528 KB | Output is correct |
8 | Correct | 22 ms | 8760 KB | Output is correct |
9 | Correct | 24 ms | 8528 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 33 ms | 14156 KB | Output is correct |
4 | Correct | 27 ms | 11852 KB | Output is correct |
5 | Correct | 0 ms | 344 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 344 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 436 KB | Output is correct |
16 | Correct | 1 ms | 348 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
18 | Correct | 32 ms | 14156 KB | Output is correct |
19 | Correct | 32 ms | 14148 KB | Output is correct |
20 | Correct | 27 ms | 12372 KB | Output is correct |
21 | Correct | 33 ms | 14120 KB | Output is correct |
22 | Correct | 33 ms | 13632 KB | Output is correct |
23 | Correct | 32 ms | 13480 KB | Output is correct |
24 | Correct | 32 ms | 13884 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 19 ms | 8016 KB | Output is correct |
3 | Correct | 24 ms | 10568 KB | Output is correct |
4 | Correct | 19 ms | 8520 KB | Output is correct |
5 | Correct | 25 ms | 10628 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 600 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 0 ms | 436 KB | Output is correct |
17 | Correct | 0 ms | 344 KB | Output is correct |
18 | Correct | 24 ms | 8200 KB | Output is correct |
19 | Correct | 19 ms | 8016 KB | Output is correct |
20 | Correct | 19 ms | 8220 KB | Output is correct |
21 | Correct | 19 ms | 8276 KB | Output is correct |
22 | Correct | 20 ms | 8212 KB | Output is correct |
23 | Correct | 23 ms | 8144 KB | Output is correct |
24 | Correct | 19 ms | 8164 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 344 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 0 ms | 348 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 16 ms | 6892 KB | Output is correct |
20 | Correct | 16 ms | 6768 KB | Output is correct |
21 | Correct | 16 ms | 6676 KB | Output is correct |
22 | Correct | 22 ms | 8792 KB | Output is correct |
23 | Correct | 22 ms | 8528 KB | Output is correct |
24 | Correct | 22 ms | 8760 KB | Output is correct |
25 | Correct | 24 ms | 8528 KB | Output is correct |
26 | Correct | 0 ms | 348 KB | Output is correct |
27 | Correct | 1 ms | 348 KB | Output is correct |
28 | Correct | 33 ms | 14156 KB | Output is correct |
29 | Correct | 27 ms | 11852 KB | Output is correct |
30 | Correct | 0 ms | 344 KB | Output is correct |
31 | Correct | 0 ms | 348 KB | Output is correct |
32 | Correct | 0 ms | 348 KB | Output is correct |
33 | Correct | 0 ms | 348 KB | Output is correct |
34 | Correct | 0 ms | 348 KB | Output is correct |
35 | Correct | 0 ms | 348 KB | Output is correct |
36 | Correct | 0 ms | 348 KB | Output is correct |
37 | Correct | 0 ms | 344 KB | Output is correct |
38 | Correct | 0 ms | 348 KB | Output is correct |
39 | Correct | 0 ms | 348 KB | Output is correct |
40 | Correct | 1 ms | 436 KB | Output is correct |
41 | Correct | 1 ms | 348 KB | Output is correct |
42 | Correct | 0 ms | 348 KB | Output is correct |
43 | Correct | 32 ms | 14156 KB | Output is correct |
44 | Correct | 32 ms | 14148 KB | Output is correct |
45 | Correct | 27 ms | 12372 KB | Output is correct |
46 | Correct | 33 ms | 14120 KB | Output is correct |
47 | Correct | 33 ms | 13632 KB | Output is correct |
48 | Correct | 32 ms | 13480 KB | Output is correct |
49 | Correct | 32 ms | 13884 KB | Output is correct |
50 | Correct | 1 ms | 344 KB | Output is correct |
51 | Correct | 19 ms | 8016 KB | Output is correct |
52 | Correct | 24 ms | 10568 KB | Output is correct |
53 | Correct | 19 ms | 8520 KB | Output is correct |
54 | Correct | 25 ms | 10628 KB | Output is correct |
55 | Correct | 0 ms | 348 KB | Output is correct |
56 | Correct | 0 ms | 348 KB | Output is correct |
57 | Correct | 0 ms | 600 KB | Output is correct |
58 | Correct | 0 ms | 348 KB | Output is correct |
59 | Correct | 0 ms | 348 KB | Output is correct |
60 | Correct | 0 ms | 348 KB | Output is correct |
61 | Correct | 0 ms | 348 KB | Output is correct |
62 | Correct | 0 ms | 348 KB | Output is correct |
63 | Correct | 0 ms | 348 KB | Output is correct |
64 | Correct | 0 ms | 348 KB | Output is correct |
65 | Correct | 0 ms | 436 KB | Output is correct |
66 | Correct | 0 ms | 344 KB | Output is correct |
67 | Correct | 24 ms | 8200 KB | Output is correct |
68 | Correct | 19 ms | 8016 KB | Output is correct |
69 | Correct | 19 ms | 8220 KB | Output is correct |
70 | Correct | 19 ms | 8276 KB | Output is correct |
71 | Correct | 20 ms | 8212 KB | Output is correct |
72 | Correct | 23 ms | 8144 KB | Output is correct |
73 | Correct | 19 ms | 8164 KB | Output is correct |
74 | Correct | 21 ms | 8536 KB | Output is correct |
75 | Correct | 20 ms | 8264 KB | Output is correct |
76 | Correct | 22 ms | 8664 KB | Output is correct |
77 | Correct | 19 ms | 8000 KB | Output is correct |
78 | Correct | 19 ms | 8268 KB | Output is correct |
79 | Correct | 19 ms | 8268 KB | Output is correct |
80 | Correct | 19 ms | 7888 KB | Output is correct |
81 | Correct | 20 ms | 8276 KB | Output is correct |
82 | Correct | 20 ms | 7984 KB | Output is correct |
83 | Correct | 22 ms | 8664 KB | Output is correct |
84 | Correct | 21 ms | 8628 KB | Output is correct |
85 | Correct | 28 ms | 8608 KB | Output is correct |
86 | Correct | 21 ms | 8740 KB | Output is correct |
87 | Correct | 21 ms | 8656 KB | Output is correct |
88 | Correct | 21 ms | 8776 KB | Output is correct |
89 | Correct | 21 ms | 8780 KB | Output is correct |
90 | Correct | 22 ms | 9016 KB | Output is correct |
91 | Correct | 21 ms | 8664 KB | Output is correct |
92 | Correct | 21 ms | 8756 KB | Output is correct |
93 | Correct | 22 ms | 8664 KB | Output is correct |
94 | Correct | 21 ms | 8760 KB | Output is correct |
95 | Correct | 21 ms | 8780 KB | Output is correct |
96 | Correct | 21 ms | 8884 KB | Output is correct |
97 | Correct | 24 ms | 8540 KB | Output is correct |
98 | Correct | 22 ms | 8760 KB | Output is correct |
99 | Correct | 22 ms | 8792 KB | Output is correct |
100 | Correct | 22 ms | 8644 KB | Output is correct |
101 | Correct | 26 ms | 8512 KB | Output is correct |
102 | Correct | 22 ms | 8612 KB | Output is correct |