QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#85037 | #5453. Mana Collection | wangzhe_0477 | 8.333333 | 393ms | 91968kb | C++23 | 3.1kb | 2023-03-06 22:02:01 | 2023-03-06 22:02:02 |
Judging History
answer
// Source: USACO 2023 January Contest (Platinum)
// Problem: Mana Collection
#include <bits/stdc++.h>
using LL = long long;
using ULL = unsigned LL;
constexpr ULL E(long double x, int y) {
while (y--) x *= 10;
return x;
}
constexpr ULL SIZE(long double x, int y) {return E(x, y) + 5;}
const int inf32 = E(1, 9) + 5;
const LL inf64 = E(1, 18) + 5;
using INT32 = int;
using INT64 = long long;
using INT128 = __int128;
struct Vector2 {
LL x, y;
Vector2() = default;
Vector2(LL _x, LL _y): x(_x), y(_y) {}
friend INT128 operator*(const Vector2 &a, const Vector2 &b) {return a.x * b.y - a.y * b.x;}
friend Vector2 operator-(const Vector2 &a, const Vector2 &b) {return {a.x - b.x, a.y - b.y};}
LL Calc(LL k) {return y - x * k;}
};
struct Maintain {
int cnt, top;
Vector2 a[1 << 18], sta[1 << 18];
void Insert(const Vector2 &x) {a[++cnt] = x;}
void Build() {
std::sort(a + 1, a + cnt + 1, [](const Vector2 &a, const Vector2 &b) {return a.x < b.x;});
for (int i = 1; i <= cnt; i++) {
while (top > 1 && (sta[top] - sta[top - 1]) * (a[i] - sta[top]) <= 0) top--;
sta[++top] = a[i];
}
}
LL Query(LL k) {
int l = 1, r = top - 1;
while (l <= r) {
int mid = (l + r) >> 1;
if (sta[mid].Calc(k) <= sta[mid + 1].Calc(k)) r = mid - 1;
else l = mid + 1;
}
return sta[r + 1].Calc(k);
}
};
int n, m, q;
Maintain ans[20];
LL sum[1 << 18], dis[20][20], f[1 << 18][20];
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%lld", &sum[1 << i]);
for (int i = 1; i < 1 << n; i++) {
int j = i & -i;
sum[i] = sum[i ^ j] + sum[j];
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
dis[i][j] = inf64;
for (int i = 1; i <= m; i++) {
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
dis[x - 1][y - 1] = std::min(dis[x - 1][y - 1], static_cast<LL>(z));
}
for (int k = 0; k < n; k++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
dis[i][j] = std::min(dis[i][j], dis[i][k] + dis[k][j]);
for (int i = 0; i < 1 << n; i++)
for (int j = 0; j < n; j++)
f[i][j] = inf64;
for (int i = 0; i < n; i++) f[1 << i][i] = 0;
for (int s = 1; s < 1 << n; s++)
for (int i = 0; i < n; i++) {
if (f[s][i] == inf64) continue;
for (int j = 0; j < n; j++) {
if (s >> j & 1) continue;
if (dis[i][j] == inf64) continue;
f[s | 1 << j][j] = std::min(f[s | 1 << j][j], f[s][i] + sum[s] * dis[i][j]);
}
}
for (int s = 1; s < 1 << n; s++)
for (int i = 0; i < n; i++) {
if (f[s][i] == inf64) continue;
ans[i].Insert({sum[s], f[s][i]});
}
for (int i = 0; i < n; i++) ans[i].Build();
scanf("%d", &q);
for (int i = 1; i <= q; i++) {
int s, e;
scanf("%d%d", &s, &e);
printf("%lld\n", -ans[e - 1].Query(s));
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 4.16667
Accepted
time: 2ms
memory: 3544kb
input:
2 1 1 10 1 2 10 4 5 1 5 2 100 1 100 2
output:
5 50 100 1090
result:
ok 4 number(s): "5 50 100 1090"
Test #2:
score: 4.16667
Accepted
time: 2ms
memory: 3532kb
input:
4 8 50000000 100000000 20000000 70000000 1 2 20 2 1 50 2 3 90 1 3 40 3 1 10 4 1 25 1 4 5 4 3 70 3 8 3 1000000000 1 500000 4
output:
160000000 239999988050000000 119992550000000
result:
ok 3 number(s): "160000000 239999988050000000 119992550000000"
Test #3:
score: 0
Wrong Answer
time: 2ms
memory: 3856kb
input:
10 90 95677166 99413032 90081107 97391055 96848266 92520734 90623124 96509760 95451402 99152599 1 10 94105173 3 9 91922842 5 2 90862613 8 3 94419460 4 7 90084016 6 4 90693719 10 8 97125103 2 1 93286961 5 10 91546334 4 8 92053784 8 5 96537357 3 1 95913083 1 3 95054163 2 8 95986698 7 6 95233705 8 10 9...
output:
-160505816817071087 435475953145144199 200595475148225200 238286336608247483 122457948714754995 11582481992637226 47368104449435476 9712791232257035 377619800822577680 12031833144588009 179764970550021158 -88173180862635821 -28300699802266159 317665507942407542 107689595558291510 -122430112187613665...
result:
wrong answer 1st numbers differ - expected: '11703326493772984', found: '-160505816817071087'
Test #4:
score: 0
Wrong Answer
time: 3ms
memory: 4060kb
input:
10 90 48104151 45958764 10384927 58976477 4508220 48401738 63414134 56241331 43456656 5364282 4 3 34321182 3 8 6111111 10 3 89336838 7 6 15869517 9 6 45416322 6 8 65416493 8 7 68165563 1 10 17098910 5 7 23144280 10 5 41059929 4 5 83655589 8 2 11141593 10 4 47789741 6 4 15702833 6 5 3119771 9 5 79973...
output:
3304702166591849 30302810727305180 4586294248391907 3962115231829842 1121889828581088 9265265357185194 281310401340040631 14702388836306286 42047169931844190 -699112482137134 3290497510645790 374184651748191311 964047290046821 -320272324212970 27383209220106676 -5903817587599428 34262253119820690 43...
result:
wrong answer 1st numbers differ - expected: '3586313126541447', found: '3304702166591849'
Test #5:
score: 0
Wrong Answer
time: 54ms
memory: 3936kb
input:
10 87 61275784 16282886 58999609 52155395 53012427 89533414 15431931 35150033 58505854 59445220 9 5 3496028 7 6 17372183 8 1 287847 2 7 19991219 4 5 40820118 4 9 38405375 1 4 52061958 1 3 95765844 9 7 88432897 10 3 62181295 2 4 2070594 6 8 38490628 5 1 74834920 5 2 58054124 5 10 53052912 9 10 799932...
output:
15085771988076394 14251451329773145 8525943703644941 16377976633798814 -7879334055848133 1005601456744669 6852742614908293 -6263821750124396 228386818476732630 -12371407115232675 29238901809451522 6785872789793534 17366398011471077 14730768570927101 -1020870526100048 16987719375043021 12491425537292...
result:
wrong answer 1st numbers differ - expected: '18729278111132298', found: '15085771988076394'
Test #6:
score: 0
Wrong Answer
time: 65ms
memory: 4088kb
input:
10 90 95356560 91592390 93197917 98740065 97680300 92412698 94329246 97243226 90272368 97469569 10 6 99745186 9 3 93877572 4 3 95758698 6 10 91855996 5 1 90121278 5 4 95076290 8 2 99231614 10 3 93399573 4 1 91994993 6 5 94052740 5 2 96068955 2 10 91338395 7 10 91890588 4 7 94880828 1 6 96554961 7 5 ...
output:
159407460084106797 158889128200321254 314608459215663952 27628389571437969 94231802724156575 -27131858957875546 -228429391390378199 42675281241371525 369797341610245871 -6436246356082735 -100875913627804805 480422105647670249 -2190638569253935 220695044256426336 94369809008229465 241757323351017107 ...
result:
wrong answer 1st numbers differ - expected: '163280051600495389', found: '159407460084106797'
Test #7:
score: 0
Wrong Answer
time: 74ms
memory: 3912kb
input:
10 89 93795458 90122950 90809309 91512557 99759510 98879743 90406791 91988172 98723686 97265654 3 1 92410620 6 10 787488884 1 7 872243221 5 10 93057933 8 3 90945371 7 4 94869387 1 4 90377187 9 1 92060643 10 8 98532700 9 5 97326866 10 2 98947943 1 6 96415500 10 4 92676865 8 7 92985312 9 6 98444476 1 ...
output:
73249105452768236 -130844053335756911 19314270887779981 27692175491361791 55909487499531095 164673786040384904 278837132944765932 113102714373134657 7507829094601003 344678097833539445 74110772249854541 -169975274961290309 255063468097789261 313083745549021695 178085641574048036 84439416467507895 36...
result:
wrong answer 1st numbers differ - expected: '96011873276486328', found: '73249105452768236'
Test #8:
score: 0
Wrong Answer
time: 52ms
memory: 3852kb
input:
10 89 1382293 67193843 93859961 477481 92652257 99885499 50256117 70192761 34119368 16710544 9 10 42167550 5 8 37587488 6 1 39681485 2 6 83885591 2 8 63502599 2 7 96584704 3 2 28849619 1 2 89615158 7 6 49082361 6 7 6114228 6 10 45456432 7 4 87603741 1 8 8377024 5 9 3400067 10 4 42824742 8 1 34659500...
output:
-7420375082472551 44473794879167166 34795660921406235 27317723188808 39115307929039894 84757007961794433 23661019484267725 720752115223263 22519797839536703 33452321319032245 35012500150605 613628626300050 13461926383661340 998405266972404 -12878060246461519 1581856764360885 -27389166465806627 77813...
result:
wrong answer 1st numbers differ - expected: '5212184985750879', found: '-7420375082472551'
Test #9:
score: 0
Wrong Answer
time: 70ms
memory: 3912kb
input:
10 90 97766575 91352441 94775266 90513638 95828190 90356289 90495007 98680228 93010243 98543991 1 3 99109059 5 8 90074960 6 5 90055463 6 1 90819495 8 9 98346448 8 5 90223065 10 9 92780029 3 6 90250424 9 1 96050114 7 3 90956675 4 2 92037130 4 7 90691071 2 3 91565269 8 3 94131990 2 9 97006947 4 10 942...
output:
-41495155673060342 175007490297216232 -80802891482841170 14983578016321279 175007490297216232 19975944439020152 -36161765258139592 188889907789248842 159309837481951878 -56564368167374902 173235306547532797 70956588106343578 -23861617004015591 110402260807611629 148431546173397828 41578781114930570 ...
result:
wrong answer 1st numbers differ - expected: '8773129927176957', found: '-41495155673060342'
Test #10:
score: 0
Wrong Answer
time: 334ms
memory: 83784kb
input:
18 306 97592575 5845225 97094410 61652068 60514373 77053365 82408570 65859870 52309184 11075991 79663473 60429988 64440299 88087418 51883591 39638284 31941363 95790465 18 7 12121248 13 6 28252098 14 12 2481192 4 16 54868108 13 15 33001477 7 13 15911113 8 16 47075458 7 14 51352052 9 2 41100503 18 10 ...
output:
44779900310960854 -3562946412437319 21813822500513617 -5520620836914119 -10189620116366442 11831337854933588 30213003443498889 -5979968658815666 6328919880181024 10098017276875790 -2724760519094327 -4686967134025041 -17122264476156537 20106734860478228 30201427358245162 32959381857527506 13830489758...
result:
wrong answer 1st numbers differ - expected: '56264701460108257', found: '44779900310960854'
Test #11:
score: 0
Wrong Answer
time: 334ms
memory: 84292kb
input:
18 306 54786856 23623482 37443275 34976477 27052191 21997277 93803298 62986079 72289998 36640646 66962609 75940630 20835955 36012773 32492294 69398349 49378951 13097897 7 10 5470000 8 7 53513890 3 15 38460382 7 16 19142503 5 14 45517218 18 17 42648313 8 18 48305235 4 16 41424027 5 12 52928903 5 4 44...
output:
11897606484930929 28314927736402616 -6258322086705997 14803236556621203 8514485896799692 19417972610920891 -699257100720426 11502230521884759 -1867709098304603 -4062516247081417 1022159515842459 23068308785333223 1192043300182400 4137981963812320 13173867998279572 33839724935849088 1991341194797418 ...
result:
wrong answer 1st numbers differ - expected: '16448924998323876', found: '11897606484930929'
Test #12:
score: 0
Wrong Answer
time: 315ms
memory: 84440kb
input:
18 303 87437585 22204459 77335222 63373455 24384957 40111770 61538701 65736765 65450807 20008686 60461910 77184085 62951808 75441264 35010255 67513271 41855413 84760939 6 14 45984925 3 6 5610402 8 1 49203830 8 3 53792394 10 8 11629718 1 12 20708032 4 6 14035635 15 18 487975772 3 1 28292662 3 10 2399...
output:
-4040400901073836 21509755845418732 8029804042982903 339914624477044628 4561469176010845 3466332070112183 3798263948527692 4904399192221330 6618234818931874 549385721450461124 5805290463054070 6775950657892415 6724989814396930 24880512271188440 -4234192287995588 3342128733686959 29355794212389308 25...
result:
wrong answer 1st numbers differ - expected: '1107904896715516', found: '-4040400901073836'
Test #13:
score: 0
Wrong Answer
time: 327ms
memory: 84904kb
input:
18 300 95399651 98514702 95906995 99120696 97373712 99841892 95487998 98629037 97207398 99163728 97816361 94919203 95202846 96133518 98849047 99498436 94447669 96164861 10 8 54922237 1 2 55368382 10 4 54029624 9 8 55267410 14 2 53427574 14 18 54579322 3 9 54230956 2 9 52630731 4 16 53837522 3 7 8372...
output:
-72637676010774072 11335001542190416 508480515653587237 295181387773007696 46853453554732356 382105254365506127 289452425666173686 116798731709044687 458367614623370007 -256763894275679629 542951107108099070 56663190188745787 -219979961428058861 225425608734785161 460465443990818916 2507381054647125...
result:
wrong answer 1st numbers differ - expected: '109547258785001075', found: '-72637676010774072'
Test #14:
score: 0
Wrong Answer
time: 339ms
memory: 85056kb
input:
18 306 94983318 99500146 99056770 99199070 96785433 94689368 96603811 97464542 96757856 95575432 97758260 96271537 94822391 98897205 96531324 95046283 95759027 99689250 14 18 54518764 3 8 54402270 16 8 52601874 3 11 52679529 13 6 54902169 1 10 54363631 4 2 55268135 5 6 52963284 16 1 52494958 12 11 5...
output:
202018052952267947 143813469135282428 122324532619620048 -53315054509658468 184232600434313220 -10892132661466581 169657863343114792 208187278929280535 31144398362768198 -283562536350834904 463611789047013842 -207938568884249362 473744358660974686 324790996118026140 -190447486637887895 3018413543321...
result:
wrong answer 1st numbers differ - expected: '233314656911878890', found: '202018052952267947'
Test #15:
score: 0
Wrong Answer
time: 151ms
memory: 30808kb
input:
16 240 47666600 44327219 49953274 41785108 32073587 24424080 30939819 78762914 90224099 59998405 64133109 48652631 22221281 96356764 38490560 116991 1 2 91993819 1 3 97619874 1 4 89451708 1 5 79740187 1 6 94041352 1 7 78606419 1 8 126429514 1 9 137890699 1 10 107665005 1 11 111799709 1 12 96319231 1...
output:
212540929497153000 67107116385111426 160830745949979663 58791727813832608 95764761271748279 175339139652863002 239297214240271800 264345302513412638 25916559560778064 108527092089074230 229728402202110570 171112061109054276 127390525466717280 102215300925877906 110949777479288000 8928107215433348 19...
result:
wrong answer 29th numbers differ - expected: '3444904053673470', found: '3444116958815886'
Test #16:
score: 0
Wrong Answer
time: 141ms
memory: 22776kb
input:
16 240 42361838 31647618 32114308 8782634 17345648 68132951 88405030 26942819 62741100 66985295 20876520 8437021 27114112 66925976 7183979 94977427 2 15 58174648 8 15 34276605 6 10 58212397 2 13 58804593 13 9 54225029 15 14 33719184 11 13 61087050 9 10 28955627 6 2 10289499 10 2 20518981 13 8 837959...
output:
231881949783065191 13654289586189282 -852215425408615 -2824515953673761 -512107978003949 5670560113574638 5766391356806328 12406228572527 -3621073645622399 4394842316935579 7972161782551138 9402518083752431 2202344939569318 -4934017854670106 10047209421291290 11319678805741861 12483657474563341 8689...
result:
wrong answer 1st numbers differ - expected: '493210283393155328', found: '231881949783065191'
Test #17:
score: 0
Wrong Answer
time: 127ms
memory: 22816kb
input:
16 240 94916675 95328982 94461789 98179130 96410042 95984504 99026406 96722757 98043813 97126519 99521857 99735210 99833885 94048501 93989630 97045699 5 6 61339353 7 11 61447467 16 7 59391553 15 5 61958471 13 2 59603541 13 16 60250166 2 3 61615858 16 3 60312774 14 6 61619256 9 2 61767236 7 12 608785...
output:
604799722993852346 48979899220947080 41430958145056370 -55514002934638876 24271770616978748 106367202036216788 -231455934608632359 250416898240632367 373399780726185367 -147031958280494086 396824312764772915 205909066980593656 334175351256258109 483008343190589165 40397837766186569 52193853677804094...
result:
wrong answer 1st numbers differ - expected: '690101190008603503', found: '604799722993852346'
Test #18:
score: 0
Wrong Answer
time: 230ms
memory: 42944kb
input:
17 269 10989016 28905152 56011456 36383994 32588074 40160206 81943847 29653018 81874689 11531228 28812650 79088847 31042740 89163087 58731031 57356809 5076315 2 4 54972232 1 17 48426734 17 8 7126979 7 2 16376090 10 7 30672058 8 17 55225752 2 6 312152706 4 12 1609956 11 10 44726737 7 6 16333848 17 9 ...
output:
3347152320800888 -140993432754634 3761913242079425 -2879298199275857 4689946105917250 -498543417405521 -1105416227381084 -2042886302315923 4678007442473398 55555783339067018 2674460598503669 17005089598495987 18975156991269805 -9599798457245715 -12425394514671592 55413657920346832 -6351223149131413 ...
result:
wrong answer 1st numbers differ - expected: '5581509823816012', found: '3347152320800888'
Test #19:
score: 0
Wrong Answer
time: 219ms
memory: 45972kb
input:
17 241 20878633 21727433 30788417 1919362 24415556 26527489 14285320 3437901 23517959 28616698 11361867 15220890 21496568 20470194 31073215 5981317 11566475 1 2 42606066 1 3 98682648 1 4 22797995 1 5 45294189 1 6 47406122 1 7 35163953 1 8 24316534 1 9 44396592 1 10 49495331 1 11 32240500 1 12 360995...
output:
100413716306850912 39998804782948735 7253589755190765 47159747035437894 118511594325190800 4126981818415894 17898559608714996 127334375674217127 74796399027851904 123844232555199870 98643742379287216 -527610088693730 154697776830457968 6746668007569464 98952498834925632 44351325877615764 18444536869...
result:
wrong answer 1st numbers differ - expected: '108874984881706836', found: '100413716306850912'
Test #20:
score: 0
Wrong Answer
time: 212ms
memory: 46280kb
input:
17 241 26896510 11416857 23632920 22663714 10426416 1449988 6534437 21431904 6332558 5350871 7478640 7144884 1667707 31989074 24328111 14606283 16379885 1 2 38313367 1 3 50529430 1 4 89019020 1 5 37322926 1 6 28346498 1 7 33430947 1 8 48328414 1 9 33229068 1 10 32247381 1 11 48235649 1 12 34041394 1...
output:
32662881441116048 43468851513345782 76907369630319617 60538368609983277 83332960672446882 32641282900987092 10044396653445154 20218272955037770 47761393742370 69808758556166324 159872167346625392 104152871208486600 107065318334030444 83090553764124330 145016744327852774 2500290056083200 923960936011...
result:
wrong answer 1st numbers differ - expected: '32779028068219037', found: '32662881441116048'
Test #21:
score: 0
Wrong Answer
time: 368ms
memory: 91180kb
input:
18 273 5856998 26869251 1761061 23339731 6696975 12073312 26103914 9146585 14284107 2290011 33149581 6690606 1938529 2611081 4180578 15507572 12766646 8196720 1 2 32726249 1 3 7618059 1 4 29196729 1 5 12553973 1 6 17930310 1 7 31960912 1 8 15003583 1 9 20141105 1 10 8147009 1 12 12547604 1 13 779552...
output:
58865157325487066 11829620092917720 88494791222904508 39396363355171172 3287054248487086 93985077914518126 361398308583375 42253585547878983 119610905416381014 163088132806547341 137544098765039761 8905421058615476 135232277169228054 30697972443940536 90242487681031400 13349308698897930 481211077143...
result:
wrong answer 1st numbers differ - expected: '59668433821480730', found: '58865157325487066'
Test #22:
score: 0
Wrong Answer
time: 393ms
memory: 90852kb
input:
18 273 18655021 10530209 4072104 27397860 1799797 31844906 10224838 22363503 8387103 25160565 867464 18587455 28492008 3583506 7250222 12947265 13542506 15353338 1 2 29185230 1 3 22727125 1 4 46052881 1 5 20454818 1 6 50499927 1 8 41018524 1 9 44747129 1 10 43815586 1 11 28438355 1 12 37242476 1 13 ...
output:
171634263103273186 165631875143373062 138395924148238130 60988972454797383 2732703036051690 151856270315873912 6690060573976643 50836174460681764 128208751394241908 -1741500694604708 14888573155075312 5461385712679200 40058934615929502 12018441115504480 50268139752969840 15564070638837750 1156797081...
result:
wrong answer 1st numbers differ - expected: '191914217942017249', found: '171634263103273186'
Test #23:
score: 0
Wrong Answer
time: 376ms
memory: 91968kb
input:
18 273 18425031 23650394 24880771 20922906 26575943 17784399 1257646 4304768 2028569 32225860 3162758 23575563 21688821 6218252 30502483 720206 33244851 27314277 1 2 43683269 1 3 61643789 1 4 75113213 1 5 58792271 1 6 52052510 1 7 28904939 1 8 22817172 1 9 26122275 1 11 24226530 1 12 77523542 1 13 6...
output:
1138546366805558 56157393424452300 38630280985221198 27245035011159108 78378034351839984 113095555313189897 25210206161932176 134218174568525436 541758543668230 105468096306484779 165706261175145399 167483536627710179 -4811008059040788 8396245939966392 3553880571700093 84344483956017620 178823205177...
result:
wrong answer 2nd numbers differ - expected: '62673090797446448', found: '56157393424452300'
Test #24:
score: 0
Wrong Answer
time: 362ms
memory: 90856kb
input:
18 273 26613501 27441209 12794702 13658897 32546072 2607103 21792275 12508707 8092259 2836952 26658654 15275240 16574454 31623641 1150608 21764569 30050392 12599166 1 2 54054710 1 3 39408203 1 4 40272398 1 5 59159573 1 6 29220604 1 7 48405776 1 9 34705760 1 10 29450453 1 11 53272155 1 12 41888741 1 ...
output:
2235334914758655 48604051997129268 518275850449560 2587198055659784 621124080632040 188007108199283076 8732146742783067 95638860277392900 82967843019910928 165339991802812500 162632332510855528 103793644457626412 206743176660941360 34505908422228718 86106598826358172 59784192120498405 31244594810364...
result:
wrong answer 1st numbers differ - expected: '2709709040134800', found: '2235334914758655'