Task: | Keke's delivery service |
Sender: | aalto2024k_003 |
Submission time: | 2024-11-13 17:15:53 +0200 |
Language: | C++ (C++20) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.27 s | details |
#2 | ACCEPTED | 0.27 s | details |
#3 | ACCEPTED | 0.27 s | details |
#4 | ACCEPTED | 0.27 s | details |
#5 | ACCEPTED | 0.27 s | details |
#6 | ACCEPTED | 0.27 s | details |
#7 | ACCEPTED | 0.27 s | details |
#8 | ACCEPTED | 0.27 s | details |
#9 | ACCEPTED | 0.27 s | details |
#10 | ACCEPTED | 0.27 s | details |
#11 | ACCEPTED | 0.27 s | details |
#12 | ACCEPTED | 0.27 s | details |
#13 | ACCEPTED | 0.27 s | details |
#14 | ACCEPTED | 0.27 s | details |
#15 | ACCEPTED | 0.27 s | details |
#16 | ACCEPTED | 0.27 s | details |
#17 | ACCEPTED | 0.27 s | details |
#18 | ACCEPTED | 0.27 s | details |
#19 | ACCEPTED | 0.27 s | details |
#20 | ACCEPTED | 0.27 s | details |
#21 | ACCEPTED | 0.28 s | details |
#22 | ACCEPTED | 0.27 s | details |
#23 | ACCEPTED | 0.27 s | details |
#24 | ACCEPTED | 0.27 s | details |
#25 | ACCEPTED | 0.27 s | details |
#26 | ACCEPTED | 0.27 s | details |
#27 | ACCEPTED | 0.27 s | details |
#28 | ACCEPTED | 0.27 s | details |
#29 | ACCEPTED | 0.27 s | details |
#30 | ACCEPTED | 0.27 s | details |
#31 | ACCEPTED | 0.27 s | details |
#32 | ACCEPTED | 0.27 s | details |
#33 | ACCEPTED | 0.27 s | details |
#34 | ACCEPTED | 0.27 s | details |
#35 | ACCEPTED | 0.27 s | details |
#36 | ACCEPTED | 0.27 s | details |
#37 | ACCEPTED | 0.27 s | details |
#38 | ACCEPTED | 0.27 s | details |
#39 | ACCEPTED | 0.27 s | details |
#40 | ACCEPTED | 0.28 s | details |
#41 | ACCEPTED | 0.28 s | details |
#42 | ACCEPTED | 0.27 s | details |
#43 | ACCEPTED | 0.28 s | details |
#44 | ACCEPTED | 0.28 s | details |
#45 | ACCEPTED | 0.28 s | details |
#46 | ACCEPTED | 0.28 s | details |
#47 | ACCEPTED | 0.28 s | details |
#48 | ACCEPTED | 0.29 s | details |
#49 | ACCEPTED | 0.30 s | details |
#50 | ACCEPTED | 0.29 s | details |
#51 | ACCEPTED | 0.30 s | details |
#52 | ACCEPTED | 0.30 s | details |
#53 | ACCEPTED | 0.35 s | details |
#54 | ACCEPTED | 0.35 s | details |
#55 | ACCEPTED | 0.35 s | details |
#56 | ACCEPTED | 0.36 s | details |
#57 | ACCEPTED | 0.36 s | details |
#58 | ACCEPTED | 0.35 s | details |
#59 | ACCEPTED | 0.36 s | details |
#60 | ACCEPTED | 0.36 s | details |
#61 | ACCEPTED | 0.35 s | details |
#62 | ACCEPTED | 0.35 s | details |
Code
#include <bits/stdc++.h> #include <iomanip> #include <vector> using namespace std; #define int long long #define rep(i, a, b) for(int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef long double ld; string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif /** * Author: Ulf Lundstrom * Date: 2009-02-26 * License: CC0 * Source: My head with inspiration from tinyKACTL * Description: Class to handle points in the plane. * T can be e.g. double or long long. (Avoid int.) * Status: Works fine, used a lot */ template <class T> int sgn(T x) { return (x > 0) - (x < 0); } template<class T> struct Point { typedef Point P; T x, y; explicit Point(T x=0, T y=0) : x(x), y(y) {} bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); } bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); } P operator+(P p) const { return P(x+p.x, y+p.y); } P operator-(P p) const { return P(x-p.x, y-p.y); } P operator*(T d) const { return P(x*d, y*d); } P operator/(T d) const { return P(x/d, y/d); } T dot(P p) const { return x*p.x + y*p.y; } T cross(P p) const { return x*p.y - y*p.x; } T cross(P a, P b) const { return (a-*this).cross(b-*this); } T dist2() const { return x*x + y*y; } double dist() const { return sqrt((double)dist2()); } // angle to x-axis in interval [-pi, pi] double angle() const { return atan2(y, x); } P unit() const { return *this/dist(); } // makes dist()=1 P perp() const { return P(-y, x); } // rotates +90 degrees P normal() const { return perp().unit(); } // returns point rotated 'a' radians ccw around the origin P rotate(double a) const { return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); } friend ostream& operator<<(ostream& os, P p) { return os << "(" << p.x << "," << p.y << ")"; } }; const int N = 10; int n; Point<int> a[N], b[N]; ld dp[1 << N][1 << N][2 * N]; const ld INF = 1e30; signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); // RTE if input wrong datatype int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i].x >> a[i].y; cin >> b[i].x >> b[i].y; } for (int j = 0; j < (1 << N); j++) { for (int jj = 0; jj < (1 << N); jj++) { for (int i = 0; i < 2*N; i++) { dp[j][jj][i] = INF; } } } Point<int> origin = Point(0LL, 0LL); // start at any begin is dist from that to start for (int i = 0; i < n; i++) { dp[1 << i][0][i] = (a[i] - origin).dist(); } ld ans = INF; for (int amsk = 0; amsk < (1 << n); amsk++) { vector<int> nxt; for (int bmsk = amsk; ; bmsk = (bmsk - 1) & amsk) { nxt.push_back(bmsk); if (bmsk == 0) break; } reverse(all(nxt)); for (int bmsk : nxt) { for (int pos = 0; pos < 2 * n; pos++) { if (pos >= n) { // end int i = pos - n; if (!(bmsk >> i & 1)) continue; int nbmsk = bmsk ^ (1 << i); // go from another start for (int j = 0; j < n; j++) { if (amsk >> j & 1) { dp[amsk][bmsk][pos] = min(dp[amsk][bmsk][pos], dp[amsk][nbmsk][j] + (b[i] - a[j]).dist()); } } // go from another end for (int j = 0; j < n; j++) { if (nbmsk >> j & 1) { dp[amsk][bmsk][pos] = min(dp[amsk][bmsk][pos], dp[amsk][nbmsk][j+n] + (b[i] - b[j]).dist()); } } } else { // start int i = pos; if (!(amsk >> i & 1)) continue; int namsk = amsk ^ (1 << i); // go from another start for (int j = 0; j < n; j++) { if (namsk >> j & 1) { dp[amsk][bmsk][i] = min(dp[amsk][bmsk][i], dp[namsk][bmsk][j] + (a[j] - a[i]).dist()); } } // go from another end for (int j = 0; j < n; j++) { if (bmsk >> j & 1) { dp[amsk][bmsk][i] = min(dp[amsk][bmsk][i], dp[namsk][bmsk][j+n] + (b[j] - a[i]).dist()); } } } // debug(bitset<N>(amsk).to_string(), bitset<N>(bmsk).to_string(), pos, dp[amsk][bmsk][pos]); } } } for (int i = n; i < 2*n; i++) { ans = min(ans, dp[(1<<n)-1][(1<<n)-1][i] + (b[i-n] - origin).dist()); } cout << fixed << setprecision(10) << ans; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
1 1 2 5 7 |
correct output |
---|
17.24151748197526515596 |
user output |
---|
17.2415174820 |
Test 2
Verdict: ACCEPTED
input |
---|
1 -2 10 5 9 |
correct output |
---|
27.56473698003804521928 |
user output |
---|
27.5647369800 |
Test 3
Verdict: ACCEPTED
input |
---|
2 -1 -7 -10 9 1 9 -1 0 |
correct output |
---|
46.64817201984418185146 |
user output |
---|
46.6481720198 |
Test 4
Verdict: ACCEPTED
input |
---|
2 1 -9 4 7 -4 -8 0 1 |
correct output |
---|
38.53321457061962859031 |
user output |
---|
38.5332145706 |
Test 5
Verdict: ACCEPTED
input |
---|
2 6 2 -6 8 7 8 10 -7 |
correct output |
---|
58.49347834429028263753 |
user output |
---|
58.4934783443 |
Test 6
Verdict: ACCEPTED
input |
---|
2 6 2 -6 8 7 8 10 -7 |
correct output |
---|
58.49347834429028263753 |
user output |
---|
58.4934783443 |
Test 7
Verdict: ACCEPTED
input |
---|
3 10 8 1 -7 10 7 5 2 4 2 -6 -8 |
correct output |
---|
47.94841075476520489418 |
user output |
---|
47.9484107548 |
Test 8
Verdict: ACCEPTED
input |
---|
3 -6 -9 8 7 -6 -3 9 10 0 -9 2 -2 |
correct output |
---|
53.42086935541394488933 |
user output |
---|
53.4208693554 |
Test 9
Verdict: ACCEPTED
input |
---|
3 8 9 -4 -6 7 -9 -10 -3 -8 10 2 -8 |
correct output |
---|
75.43730966940650396746 |
user output |
---|
75.4373096694 |
Test 10
Verdict: ACCEPTED
input |
---|
3 8 4 2 -1 -5 -8 -7 -7 -2 -7 -8 -5 |
correct output |
---|
41.03401888405835429979 |
user output |
---|
41.0340188841 |
Test 11
Verdict: ACCEPTED
input |
---|
3 -4 4 0 -4 6 1 6 -8 8 -8 -7 -6 |
correct output |
---|
51.02746211319720185187 |
user output |
---|
51.0274621132 |
Test 12
Verdict: ACCEPTED
input |
---|
3 -1 -1 -4 4 -6 -5 -5 -10 7 4 -8 0 |
correct output |
---|
49.16957315214831639866 |
user output |
---|
49.1695731521 |
Test 13
Verdict: ACCEPTED
input |
---|
3 5 -9 2 5 9 7 -7 8 6 -9 -3 9 |
correct output |
---|
56.01093630215238362152 |
user output |
---|
56.0109363022 |
Test 14
Verdict: ACCEPTED
input |
---|
4 -9 -6 6 -4 -1 10 5 -1 10 -4 1 -5 0 -9 -9 -2 |
correct output |
---|
69.46799309053363308958 |
user output |
---|
69.4679930905 |
Test 15
Verdict: ACCEPTED
input |
---|
4 8 -10 10 -5 8 -3 1 7 -6 -2 -10 2 -1 6 -2 -2 |
correct output |
---|
62.32599841627421704063 |
user output |
---|
62.3259984163 |
Test 16
Verdict: ACCEPTED
input |
---|
4 -10 -3 0 0 0 -10 -8 -4 -8 -10 -6 8 -2 -8 -5 -8 |
correct output |
---|
49.37474628842959419733 |
user output |
---|
49.3747462884 |
Test 17
Verdict: ACCEPTED
input |
---|
4 9 -10 3 -3 5 -10 -8 6 -9 -3 6 8 -4 5 1 4 |
correct output |
---|
70.54491148050797239000 |
user output |
---|
70.5449114805 |
Test 18
Verdict: ACCEPTED
input |
---|
4 3 2 0 9 1 3 8 5 4 -6 5 -8 5 7 -6 10 |
correct output |
---|
55.77371783018015604511 |
user output |
---|
55.7737178302 |
Test 19
Verdict: ACCEPTED
input |
---|
4 4 5 0 7 7 5 -10 4 6 -6 1 10 -4 2 -10 0 |
correct output |
---|
58.25155150420911822143 |
user output |
---|
58.2515515042 |
Test 20
Verdict: ACCEPTED
input |
---|
4 -7 3 -4 -6 -9 3 -1 -5 7 1 9 2 5 5 6 8 |
correct output |
---|
51.95472904146592808827 |
user output |
---|
51.9547290415 |
Test 21
Verdict: ACCEPTED
input |
---|
4 8 3 -7 6 0 6 9 -8 -2 8 -9 -9 9 -6 3 -2 |
correct output |
---|
71.27875557664922673284 |
user output |
---|
71.2787555766 |
Test 22
Verdict: ACCEPTED
input |
---|
4 6 -7 1 10 -8 -6 3 -9 -9 -7 -4 -9 -2 5 1 -7 |
correct output |
---|
64.30357123791869498886 |
user output |
---|
64.3035712379 |
Test 23
Verdict: ACCEPTED
input |
---|
5 3 9 -3 -6 3 -2 -7 3 10 4 -3 2 10 9 -6 4 ... |
correct output |
---|
65.29921928785613079865 |
user output |
---|
65.2992192879 |
Test 24
Verdict: ACCEPTED
input |
---|
5 -4 -10 10 -4 6 2 10 3 -6 -3 -8 -6 9 9 -9 9 ... |
correct output |
---|
82.23748773331917538004 |
user output |
---|
82.2374877333 |
Test 25
Verdict: ACCEPTED
input |
---|
5 8 -9 -3 -2 1 -4 10 5 5 5 7 -3 -8 -1 9 -5 ... |
correct output |
---|
67.56153807887115932823 |
user output |
---|
67.5615380789 |
Test 26
Verdict: ACCEPTED
input |
---|
5 -5 4 -1 4 -2 9 -5 -8 8 5 -7 2 -10 7 10 8 ... |
correct output |
---|
86.95689997133690237602 |
user output |
---|
86.9568999713 |
Test 27
Verdict: ACCEPTED
input |
---|
5 -10 -6 6 -2 -9 -2 3 -1 -10 -8 9 5 -2 -3 -5 -2 ... |
correct output |
---|
60.24622192778474186192 |
user output |
---|
60.2462219278 |
Test 28
Verdict: ACCEPTED
input |
---|
5 -1 -1 -4 4 -6 -5 -5 -10 7 4 -8 0 3 2 -5 -5 ... |
correct output |
---|
56.09845589945781874422 |
user output |
---|
56.0984558995 |
Test 29
Verdict: ACCEPTED
input |
---|
5 5 -9 2 5 9 7 -7 8 6 -9 -3 9 -7 0 -5 -2 ... |
correct output |
---|
66.46035926536274213855 |
user output |
---|
66.4603592654 |
Test 30
Verdict: ACCEPTED
input |
---|
5 9 -8 -1 1 -6 5 2 -4 3 8 4 -9 -8 3 5 3 ... |
correct output |
---|
68.92236432287188030443 |
user output |
---|
68.9223643229 |
Test 31
Verdict: ACCEPTED
input |
---|
5 -2 8 8 9 9 8 4 -2 3 9 2 1 -6 -7 -2 -8 ... |
correct output |
---|
68.57347683433427024124 |
user output |
---|
68.5734768343 |
Test 32
Verdict: ACCEPTED
input |
---|
5 1 -10 6 7 7 -3 -8 7 2 2 1 -2 -1 -6 -1 4 ... |
correct output |
---|
67.26306049003909036388 |
user output |
---|
67.2630604900 |
Test 33
Verdict: ACCEPTED
input |
---|
6 633196515 485923574 -954265220... |
correct output |
---|
7364359200.7228123750537633895... |
user output |
---|
7364359200.7228123844 |
Test 34
Verdict: ACCEPTED
input |
---|
6 -54250287 -57195506 925370083 ... |
correct output |
---|
6070544873.2142193284817039966... |
user output |
---|
6070544873.2142191976 |
Test 35
Verdict: ACCEPTED
input |
---|
6 717786754 -23244255 -670216484... |
correct output |
---|
6236901804.9330618907697498798... |
user output |
---|
6236901804.9330618083 |
Test 36
Verdict: ACCEPTED
input |
---|
6 -747595481 -560868740 20781968... |
correct output |
---|
6206348638.7408930636011064052... |
user output |
---|
6206348638.7408930883 |
Test 37
Verdict: ACCEPTED
input |
---|
6 369551931 -830851741 -63146575... |
correct output |
---|
7466232851.6345729152671992778... |
user output |
---|
7466232851.6345727295 |
Test 38
Verdict: ACCEPTED
input |
---|
7 -503438465 -401188031 -2915208... |
correct output |
---|
7182008964.6697172718122601509... |
user output |
---|
7182008964.6697172523 |
Test 39
Verdict: ACCEPTED
input |
---|
7 -774852389 498112692 -73382627... |
correct output |
---|
7322574754.7929240637458860874... |
user output |
---|
7322574754.7929239869 |
Test 40
Verdict: ACCEPTED
input |
---|
7 -745557241 -362230062 11872950... |
correct output |
---|
7345290128.8702740180306136608... |
user output |
---|
7345290128.8702741563 |
Test 41
Verdict: ACCEPTED
input |
---|
7 -280510503 487323735 82609299 ... |
correct output |
---|
8284167601.0197063554078340530... |
user output |
---|
8284167601.0197063535 |
Test 42
Verdict: ACCEPTED
input |
---|
7 -194568921 -912512861 44703011... |
correct output |
---|
9098246106.3207166725769639015... |
user output |
---|
9098246106.3207165673 |
Test 43
Verdict: ACCEPTED
input |
---|
8 383287698 969195218 -182348842... |
correct output |
---|
7016551085.8444829522632062435... |
user output |
---|
7016551085.8444828242 |
Test 44
Verdict: ACCEPTED
input |
---|
8 -385704087 -937741013 -3077950... |
correct output |
---|
8127710933.8054637983441352844... |
user output |
---|
8127710933.8054639250 |
Test 45
Verdict: ACCEPTED
input |
---|
8 844450667 -871888619 -19960889... |
correct output |
---|
8213584640.6935460437089204788... |
user output |
---|
8213584640.6935458165 |
Test 46
Verdict: ACCEPTED
input |
---|
8 -466328566 481082051 -33685140... |
correct output |
---|
9423990911.6089521860703825950... |
user output |
---|
9423990911.6089522541 |
Test 47
Verdict: ACCEPTED
input |
---|
8 -917189424 -579600323 67525298... |
correct output |
---|
8227519630.3055775831453502178... |
user output |
---|
8227519630.3055777624 |
Test 48
Verdict: ACCEPTED
input |
---|
9 -31221656 -526597392 -52535813... |
correct output |
---|
8856995290.3726284708827733993... |
user output |
---|
8856995290.3726285398 |
Test 49
Verdict: ACCEPTED
input |
---|
9 -23884334 -938550432 -56172498... |
correct output |
---|
7357984723.6206405288539826870... |
user output |
---|
7357984723.6206405386 |
Test 50
Verdict: ACCEPTED
input |
---|
9 -114003248 747828772 -69571861... |
correct output |
---|
7938964098.6173283923417329788... |
user output |
---|
7938964098.6173284799 |
Test 51
Verdict: ACCEPTED
input |
---|
9 166708726 -263032442 565409766... |
correct output |
---|
7766653103.2631514174863696098... |
user output |
---|
7766653103.2631515563 |
Test 52
Verdict: ACCEPTED
input |
---|
9 -325935302 409170424 652212820... |
correct output |
---|
8170515916.9658243129961192607... |
user output |
---|
8170515916.9658245649 |
Test 53
Verdict: ACCEPTED
input |
---|
10 178568022 273124119 535857466 ... |
correct output |
---|
8231356926.8400429780595004558... |
user output |
---|
8231356926.8400428668 |
Test 54
Verdict: ACCEPTED
input |
---|
10 -104452078 546885062 -99975436... |
correct output |
---|
9390756029.7148792939260601997... |
user output |
---|
9390756029.7148790807 |
Test 55
Verdict: ACCEPTED
input |
---|
10 -63708076 -602539257 -94432385... |
correct output |
---|
8497255968.9021178991533815860... |
user output |
---|
8497255968.9021177888 |
Test 56
Verdict: ACCEPTED
input |
---|
10 182829493 -848119476 520735868... |
correct output |
---|
9795917686.1810622680932283401... |
user output |
---|
9795917686.1810623631 |
Test 57
Verdict: ACCEPTED
input |
---|
10 934069847 175172315 -629139614... |
correct output |
---|
10107572824.729460356757044792... |
user output |
---|
10107572824.7294605449 |
Test 58
Verdict: ACCEPTED
input |
---|
10 -523273295 -881501593 86988338... |
correct output |
---|
9378626642.9278714880347251892... |
user output |
---|
9378626642.9278713465 |
Test 59
Verdict: ACCEPTED
input |
---|
10 917402565 -287078799 -55030325... |
correct output |
---|
9067761971.7593543389812111854... |
user output |
---|
9067761971.7593544424 |
Test 60
Verdict: ACCEPTED
input |
---|
10 -836129193 -511793054 67486286... |
correct output |
---|
9294216739.0473321685567498207... |
user output |
---|
9294216739.0473320931 |
Test 61
Verdict: ACCEPTED
input |
---|
10 875675361 -976131926 -48580743... |
correct output |
---|
10188158256.107221888378262519... |
user output |
---|
10188158256.1072220802 |
Test 62
Verdict: ACCEPTED
input |
---|
10 -977721665 -217325906 77767487... |
correct output |
---|
9173124717.6331664901226758956... |
user output |
---|
9173124717.6331664920 |