QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#99434 | #6302. Map | rgnerdplayer# | AC ✓ | 11ms | 3812kb | C++20 | 5.2kb | 2023-04-22 14:34:45 | 2023-04-22 14:34:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/priority_queue.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
/* ordered_set notes:
.order_of_key(k): Number of items strictly smaller than k
.find_by_order(k): k-th element in a set
*/
#define X first
#define Y second
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
return o >> a.X >> a.Y;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
return o << '(' << a.X << ", " << a.Y << ')';
}
#ifdef cychien
#define DE(...) do {\
fprintf(stderr, "%s - %d : (%s) = ", __PRETTY_FUNCTION__, __LINE__, #__VA_ARGS__);\
_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x) {cerr << x << '\n';}
template<typename I, typename ...T> void _DO(I&&x,T&&...tail) {cerr << x << ", "; _DO(tail...);}
#define IOS
#define debug(v) {cerr << #v << " = ["; for(auto it = (v).begin(); it != (v).end(); it++){cerr << *it; if (next(it) != (v).end()) cerr << ", "; } cerr << "]\n";}
#else
#define DE(...)
#define debug(v)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#endif
#define W(v) {for(auto it = (v).begin(); it != (v).end(); it++)cout << *it << " \n"[next(it) == (v).end()];}
#define pb emplace_back
#define mp make_pair
#define rsz resize
#define SZ(x) (ll)x.size()
#define AI(x) (x).begin(),(x).end()
#define SORT(x) sort(AI(x))
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
const int NF = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Rand(){
return uniform_int_distribution<int>(INT_MIN, INT_MAX)(rng);
}
/*
#include <atcoder/all>
using namespace atcoder;
*/
/* LazySegtree
// Example for range linear transfromation & range sum
// Monoid Property: op(F(a), F(b)) == F(op(a, b))
// Declaration: lazy_segtree<S, op, e, F, mapping, composition, id> seg(n);
struct S { // Node
mint sum;
int len;
};
S op(S x, S y){ // pull
return S{x.sum + y.sum, x.len + y.len};
}
S e(){ // e s.t. op(x, e) == x
return S{0, 1};
}
struct F {
mint a, b;
};
S mapping(F t, S x){ // push
return S{t.a * x.sum + t.b * x.len, x.len};
}
F composition(F f, F g){ // f o g
return F{f.a * g.a, f.a * g.b + f.b};
}
F id() { // id s.t. composition(F, id) == F
return F{1, 0};
}
*/
typedef pair<long double, long double> pdd;
const long double eps = 1e-12;
pdd operator+(const pdd& A, const pdd& B){
return make_pair(A.X + B.X, A.Y + B.Y);
}
pdd operator-(const pdd& A, const pdd& B){
return make_pair(A.X - B.X, A.Y - B.Y);
}
long double operator*(const pdd& A, const pdd& B){
return A.X * B.X + A.Y * B.Y;
}
long double norm2(pdd p){
return p.X * p.X + p.Y * p.Y;
}
long double dist(const pdd& A, const pdd& B){
return sqrtl(norm2(A - B));
}
pdd operator*(long double &rho, const pdd& P){
return make_pair(rho * P.X, rho * P.Y);
}
void solve(){
pdd M[4], P[4];
for (int i = 0; i < 4; i++) cin >> P[i].X >> P[i].Y;
for (int i = 0; i < 4; i++) cin >> M[i].X >> M[i].Y;
function<pdd(pdd)> f = [&](pdd p){
long double u = (p - P[0]) * (P[1] - P[0]) / norm2(P[1] - P[0]);
long double v = (p - P[0]) * (P[3] - P[0]) / norm2(P[3] - P[0]);
return M[0] + u * (M[1] - M[0]) + v * (M[3] - M[0]);
};
function<pdd(pdd)> g = [&](pdd p){
long double u = (p - M[0]) * (M[1] - M[0]) / norm2(M[1] - M[0]);
long double v = (p - M[0]) * (M[3] - M[0]) / norm2(M[3] - M[0]);
if (u > -eps && u < 1 + eps && v > -eps && v < 1 + eps)
return P[0] + u * (P[1] - P[0]) + v * (P[3] - P[0]);
else
return p;
};
long double ans = 1e11;
pdd A, B;
cin >> A.X >> A.Y >> B.X >> B.Y;
long double k;
int n;
cin >> k >> n;
vector<pdd> tela(2 * n + 1), telb(2 * n + 1);
tela[n] = A, telb[n] = B;
for (int i = 1; i <= n; i++){
tela[n + i] = f(tela[n + i - 1]);
telb[n + i] = f(telb[n + i - 1]);
}
for (int i = -1; i >= -n; i--){
tela[n + i] = g(tela[n + i + 1]);
telb[n + i] = g(telb[n + i + 1]);
}
for (int i = -n; i <= n; i++){
for (int j = -n; j <= n; j++){
if (abs(i) + abs(j) <= n){
long double tmp = k * (abs(i) + abs(j)) + dist(tela[n + i], telb[n + j]);
chmin(ans, tmp);
}
}
}
cout << ans << '\n';
}
int main() {
IOS;
cout << fixed << setprecision(30);
cerr << fixed << setprecision(30);
int T; cin >> T;
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3712kb
input:
2 0 0 0 2 4 2 4 0 0 0 0 1 2 1 2 0 2 1 4 2 1 1 0 0 0 3 6 3 6 0 0 1 1 0 3 2 2 3 0 0 4 2 0 3
output:
1.000000000000000000000000000000 1.227262335243028974871189185070
result:
ok 2 numbers
Test #2:
score: 0
Accepted
time: 6ms
memory: 3808kb
input:
100 -133 -128 -109 -134 -85 -38 -109 -32 -95 -37 -100 -35 -108 -55 -103 -57 -119 -130 -112 -44 2 73 5 -100 5 -8 1 -8 1 -100 1 -60 1 -14 3 -14 3 -60 3 -84 1 -20 2 53 -58 -78 -66 -78 -66 -34 -58 -34 -58 -34 -66 -34 -66 -78 -58 -78 -63 -50 -63 -37 4 54 52 -148 116 -148 116 -52 52 -52 53 -103 53 -71 101...
output:
9.500657499741558187009160540981 12.229731078922157670556269959405 13.000000000000000000000000000000 17.488532900375079476990025639793 13.341664064126333712548277965482 7.615773105863908285471930437183 23.409399821439250218360617061819 7.280109889280518271296310794938 21.2800377340838847151083257358...
result:
ok 100 numbers
Test #3:
score: 0
Accepted
time: 7ms
memory: 3664kb
input:
100 -173 -113 -120 -113 -120 -115 -173 -115 -173 -115 -120 -115 -120 -113 -173 -113 -162 -114 -152 -114 99 57 6 23 -75 4 -56 -77 25 -58 0 -58 -51 -69 -62 -18 -11 -7 -22 -56 -42 -25 19 27 -98 -115 -150 -147 -158 -134 -106 -102 -150 -147 -98 -115 -106 -102 -158 -134 -103 -111 -136 -134 25 50 136 -92 1...
output:
10.000000000000000000000000000000 25.483637975584367657902462589448 40.224370722237532599363518670543 18.384776310850235635230287556396 9.219544457292887310040363502139 18.027756377319946465634381560506 43.114063026280355837155378040393 52.887044352349006019753385743343 45.54119014694280033472839619...
result:
ok 100 numbers
Test #4:
score: 0
Accepted
time: 6ms
memory: 3784kb
input:
100 -12 -206 72 -188 135 -482 51 -500 19 -301 23 -301 23 -315 19 -315 88 -368 28 -248 14 87 -221 -566 -467 -566 -467 -565 -221 -565 -221 -566 -467 -566 -467 -565 -221 -565 -297 -566 -289 -566 274 18 -264 759 -339 609 -129 504 -54 654 -208 580 -208 655 -103 655 -103 580 -196 664 -211 596 8 64 -111 -3...
output:
34.246950475544242636222191933371 8.000000000000000000000000000000 45.926952286842947292128114256116 135.118466539551876304248168025879 131.973482184869245037450724566952 40.349665953953499100692603462903 15.321347728712508197423947109428 77.772275035020517211514778921355 66.738813035899370668113661...
result:
ok 100 numbers
Test #5:
score: 0
Accepted
time: 7ms
memory: 3732kb
input:
100 -235 -704 133 -704 133 -720 -235 -720 -224 -712 -40 -712 -40 -704 -224 -704 15 -711 76 -718 4 74 -467 574 -475 596 -123 724 -115 702 -274 662 -270 652 -430 588 -434 598 -458 588 -241 657 15 31 380 -3 532 -343 787 -229 635 111 503 -71 639 -163 708 -61 572 31 533 -189 613 -137 3 58 -460 -7 -488 -7...
output:
31.350081433008751306129591185368 51.967632320937980162922631421907 21.468697928146775874211349410814 38.837932076467767322780488825629 84.248187428308027466239416014560 77.929455278476058396885939316689 47.000000000000000000000000000000 74.115493725912497201269157898196 86.4671048804216890101836945...
result:
ok 100 numbers
Test #6:
score: 0
Accepted
time: 4ms
memory: 3752kb
input:
100 -1201 2822 -1197 2814 -3437 1694 -3441 1702 -3119 1860 -3117 1856 -1997 2416 -1999 2420 -1419 2709 -2491 2174 48 76 -2515 285 -2547 306 -1308 2194 -1276 2173 -2255 683 -2260 686 -2083 981 -2078 978 -1572 1753 -1392 2015 121 28 -1216 1209 -1498 -1141 -1598 -1129 -1316 1221 -1494 -823 -1494 -447 -...
output:
264.055863532879047217427626037534 290.425700450936406987745286301106 258.282400313066252128813005128904 743.737184763542665211222271182123 341.052781838823299759289042754062 400.566683662432774043482552883688 172.040799340956913079936363430988 27.770894609837870581695029592595 294.82588015208115367...
result:
ok 100 numbers
Test #7:
score: 0
Accepted
time: 6ms
memory: 3628kb
input:
100 1411 -2755 603 -3563 623 -3583 1431 -2775 716 -3477 1120 -3073 1110 -3063 706 -3467 1210 -2959 1339 -2830 2319 39 4528 -3417 4286 -4055 1908 -3153 2150 -2515 2094 -2892 2094 -3090 2832 -3090 2832 -2892 2257 -2993 4389 -3736 17 22 -180 -1673 -2172 -3665 -2164 -3673 -172 -1681 -284 -1792 -2027 -35...
output:
182.433549546129261290094980552112 96.880923053928568393355913457299 530.330085889910643304201443015700 44.011362169330773851105842453535 64.313365366181941440437697110610 7.392893666126123961446908738893 34.567810207462373608966466065340 148.850160742992533066675342467988 350.3381359161486040820765...
result:
ok 100 numbers
Test #8:
score: 0
Accepted
time: 4ms
memory: 3640kb
input:
100 11928 -18111 8928 -17411 11056 -8291 14056 -8991 11043 -10811 10793 -10111 12921 -9351 13171 -10051 10491 -14092 11923 -12413 10 92 11869 -4371 3539 5429 1299 3525 9629 -6275 8302 -3064 3647 2571 4935 3635 9590 -2000 2384 2680 3466 2644 181 91 4001 -10187 4001 -10897 9 -10897 9 -10187 838 -10629...
output:
87.479657002630678327981250674839 977.209322820567369283217828979105 94.486325059360631306581979060866 307.006514588860149800320087365435 1245.629559700635877628194236876880 532.000000000000000000000000000000 369.048777263927538949683793134682 19.554024317232545042768987464399 1509.00000000000000000...
result:
ok 100 numbers
Test #9:
score: 0
Accepted
time: 4ms
memory: 3784kb
input:
100 10303 -4099 19487 -8131 19703 -7639 10519 -3607 18394 -7495 18842 -7271 18854 -7295 18406 -7519 15852 -6248 15950 -6389 38 10 13132 -3411 17416 3393 15634 4515 11350 -2289 13143 -873 15411 3411 16533 2817 14265 -1467 16515 2577 16017 1561 198 94 -5480 10872 -6297 11294 -11361 1490 -10544 1068 -1...
output:
84.574886489291820075575589754635 999.689277678129568249776326638312 6231.529667746114486082120720311650 550.947886095034877029785747026835 182.544124658606005423555629363364 5374.296791209060125016350184523617 825.725781096656443469594677253554 1653.207429169171740035437778715277 2777.1096485374861...
result:
ok 100 numbers
Test #10:
score: 0
Accepted
time: 7ms
memory: 3812kb
input:
100 0 -30 84 12 126 -72 42 -114 0 -30 84 12 126 -72 42 -114 91 -41 100 -55 96 93 168 110 148 150 48 100 68 60 48 100 68 60 168 110 148 150 61 96 102 90 8 2 -123 129 -60 174 -15 111 -78 66 -15 111 -78 66 -123 129 -60 174 -44 115 -104 132 27 3 27 42 15 54 -75 -36 -63 -48 -63 -48 -75 -36 15 54 27 42 -4...
output:
16.643316977093238068219349656829 41.436698710201323180707388971200 39.206555615733702950531647246635 11.180339887498948482288940731166 49.729267036625424205920076303755 26.925824035672520155929032803499 50.931326312987373450269501518051 10.294055820165388755518809382750 117.885537705012823174455238...
result:
ok 100 numbers
Test #11:
score: 0
Accepted
time: 7ms
memory: 3780kb
input:
100 9725 6731 9725 11971 14965 11971 14965 6731 9725 6731 9725 11971 14965 11971 14965 6731 10293 11185 10445 9833 488 10 3833 -4831 6913 -4271 8443 -12686 5363 -13246 6913 -4271 3833 -4831 5363 -13246 8443 -12686 5209 -4960 7133 -6409 1 88 -5891 -6066 -8365 -6066 -8365 -8540 -5891 -8540 -8365 -6066...
output:
1360.517548582156289738165355629462 2119.674780139698552439142531511607 1638.601494195408551535209085159295 144.699689011414257433507657424343 1706.299211744528703471601716046280 2671.668018298680761457575272288523 1442.324859385013858692481392154150 2909.931270666027259830244133809174 5311.38635386...
result:
ok 100 numbers
Test #12:
score: 0
Accepted
time: 11ms
memory: 3628kb
input:
100 1432065 -1359744 1432065 -1359796 610089 -1359796 610089 -1359744 610089 -1359744 610089 -1359796 1432065 -1359796 1432065 -1359744 1413145 -1359747 670086 -1359765 306 12 -630899 -570942 344981 -570942 344981 -567164 -630899 -567164 -630899 -567164 344981 -567164 344981 -570942 -630899 -570942 ...
output:
41383.003943812649978895024105440825 344430.708764477038755558169214054942 597464.947160122257514558441471308470 57512.000021251275065026220545405522 180112.504983949338978277410205919296 254594.189465463647096044041973073035 13301.834367630940075599710326059721 246235.741341503873883311825920827687...
result:
ok 100 numbers
Test #13:
score: 0
Accepted
time: 7ms
memory: 3760kb
input:
100 -240497 1168822 -365542 931192 504344 473443 629389 711073 226221 683190 167481 688085 185400 903113 244140 898218 -192129 1110656 34450 941656 2 25 1729381 25950 1512625 519672 1528369 526584 1745125 32862 1536820 492965 1580974 388601 1584302 390009 1540148 494373 1660204 207517 1601591 344571...
output:
33.523773639151394361512803499181 126504.999518608850841872026649070904 57518.293697332946599942715693032369 318943.663702541675064594528521411121 169769.250005668789626156467420514673 1497.133893067348665240068328330381 23459.324991965074680422276287572458 853.347816095362503463483960786107 28.3514...
result:
ok 100 numbers
Test #14:
score: 0
Accepted
time: 7ms
memory: 3708kb
input:
100 -889209 606569 -191736 1436894 638589 739421 -58884 -90904 -58884 -90904 638589 739421 -191736 1436894 -889209 606569 -486300 891465 -464854 988546 79 18 -1226546 957048 -712144 1926170 -590407 1861553 -1104809 892431 -712144 1926170 -1226546 957048 -1104809 892431 -590407 1861553 -807239 146415...
output:
99421.584562910683878556028503226116 404181.388824374247690229822183027864 311311.528917577994661769480444490910 271785.624537060458550286057288758457 319158.191839094112879138265270739794 77725.025543495047884334780974313617 103690.241569289944855825069680577144 33781.004277552199500433971479651518...
result:
ok 100 numbers