QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#188522 | #7235. Points | ucup-team004 | RE | 269ms | 5060kb | C++20 | 4.4kb | 2023-09-25 22:26:14 | 2023-09-25 22:26:15 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
using Int = __int128;
struct Point {
Int x = 0;
Int y = 0;
Int z = 0;
};
Point operator+(const Point &a, const Point &b) {
return {a.x + b.x, a.y + b.y, a.z + b.z};
}
Point operator-(const Point &a, const Point &b) {
return {a.x - b.x, a.y - b.y, a.z - b.z};
}
Point cross(const Point &a, const Point &b) {
return {
a.y * b.z - a.z * b.y,
a.z * b.x - a.x * b.z,
a.x * b.y - a.y * b.x
};
}
Int dot(const Point &a, const Point &b) {
return a.x * b.x + a.y * b.y + a.z * b.z;
}
void solve() {
int n, k;
std::cin >> n >> k;
i64 ans = -1;
i64 set = 0;
std::vector<Point> a(n);
for (int i = 0; i < n; i++) {
int x, y, z;
std::cin >> x >> y >> z;
a[i] = {x, y, z};
}
std::set<std::array<i64, 3>> vis;
vis.insert({0, 0, 0});
auto check = [&](Point v) {
i64 g = std::gcd(std::gcd(i64(v.x), i64(v.y)), i64(v.z));
v.x /= g, v.y /= g, v.z /= g;
if (vis.count({i64(v.x), i64(v.y), i64(v.z)})) {
return;
}
vis.insert({i64(v.x), i64(v.y), i64(v.z)});
std::vector<int> p(n);
std::iota(p.begin(), p.end(), 0);
std::sort(p.begin(), p.end(),
[&](int i, int j) {
return dot(v, a[i]) > dot(v, a[j]);
});
auto update = [&]() {
Point sum;
for (int i = 0; i < k; i++) {
sum = sum + a[p[i]];
}
i64 res = dot(sum, sum);
if (res > ans) {
ans = res;
set = 0;
for (int i = 0; i < k; i++) {
set |= 1LL << p[i];
}
}
};
update();
if (k < n && dot(a[p[k - 1]], v) == dot(a[p[k]], v)) {
auto d = dot(a[p[k - 1]], v);
int l = k - 1, r = k + 1;
while (l > 0 && dot(a[p[l - 1]], v) == d) {
l--;
}
while (r < n && dot(a[p[r]], v) == d) {
r++;
}
for (int i = l; i < r; i++) {
for (int j = l; j < r; j++) {
if (i == j) {
continue;
}
Point u = cross(v, a[j] - a[i]);
Point vu = cross(v, u);
std::sort(p.begin() + l, p.begin() + r,
[&](int i, int j) {
auto di = dot(u, a[i]);
auto dj = dot(u, a[j]);
if (di != dj) {
return di > dj;
}
return dot(vu, a[i]) > dot(vu, a[j]);
});
update();
if (dot(a[p[k - 1]], u) == dot(a[p[k]], u)) {
auto d = dot(a[p[k - 1]], u);
int l = k - 1, r = k + 1;
while (l > 0 && dot(a[p[l - 1]], u) == d) {
l--;
}
while (r < n && dot(a[p[r]], u) == d) {
r++;
}
std::reverse(p.begin() + l, p.begin() + r);
update();
}
}
}
}
};
check({1, 0, 0});
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
check(cross(a[j] - a[i], {1, 0, 0}));
check(cross(a[j] - a[i], {0, 1, 0}));
}
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
for (int k = j + 1; k < n; k++) {
check(cross(a[j] - a[i], a[k] - a[i]));
check(cross(a[k] - a[i], a[j] - a[i]));
}
}
}
std::vector<int> p;
for (int i = 0; i < n; i++) {
if (set >> i & 1) {
p.push_back(i + 1);
}
}
std::cout << ans << "\n";
for (int i = 0; i < k; i++) {
std::cout << p[i] << " \n"[i == k - 1];
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
input:
2 3 1 4 2 6 4 9 7 6 4 2 3 2 7 3 2 8 2 4 4 7 9
output:
146 2 394 2 3
result:
ok Correct (2 tests)
Test #2:
score: 0
Accepted
time: 2ms
memory: 3692kb
input:
48 3 1 506486 41876 692904 165261 762859 246395 781549 425052 316880 8 2 525015 8224 970327 874558 80119 462001 290805 478077 274544 39054 312160 524182 199036 939842 834707 951223 75070 806760 548951 460563 421778 513649 561297 743730 4 1 817567 315632 508886 99778 825028 141365 311062 215938 94373...
output:
891900976505 3 5344254728649 1 6 1925054261378 4 4272030273153 1 2 5862467200611 1 2 9221910684849 1 2 3 1216569228449 1 17835055670598 1 4 5 7 1341292964490 1 29357482136450 2 3 4 5 6 1764061360298 3 538912373466 1 1312222964918 7 1300748107849 7 14803216579502 1 2 4 12152396511653 2 4 6 2738257866...
result:
ok Correct (48 tests)
Test #3:
score: 0
Accepted
time: 265ms
memory: 4956kb
input:
5 40 11 91406 989734 719664 162744 233803 716286 917527 609704 351890 282 578278 154507 39455 956096 454235 34402 773703 937545 67001 729884 613200 675806 111928 752155 594666 410066 824852 805401 682493 981233 563377 19394 647273 418154 871916 968817 401635 747220 410569 630989 482086 942247 77540 ...
output:
187060263705194 1 6 10 12 14 20 22 26 31 34 36 124998725467970 5 7 16 20 25 26 32 36 40 2195304412433 38 232358148617701 4 10 15 17 21 23 24 27 31 33 35 36 545828153932010 2 4 5 8 11 12 13 14 15 16 17 18 20 23 25 27 29 30 31 33 35 37 38 40
result:
ok Correct (5 tests)
Test #4:
score: 0
Accepted
time: 267ms
memory: 5060kb
input:
5 40 11 975201 157117 823907 377477 706020 936201 82313 746315 662425 749918 846757 36545 300634 66810 536521 646285 838896 476880 969977 890821 956051 79120 56878 358487 42853 353666 443931 210689 535541 994724 865120 233867 933178 168067 136322 925983 489035 998073 360565 716885 459314 158325 2065...
output:
166388273446435 1 2 6 7 10 11 13 27 29 34 38 1243844474979594 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 33 34 35 36 37 38 39 40 174143603315691 3 4 8 9 18 21 22 32 34 35 38 49888757165161 1 2 12 23 39 1036192198522043 2 3 4 5 6 7 8 9 10 11 12 13 15 16 17 19 20...
result:
ok Correct (5 tests)
Test #5:
score: 0
Accepted
time: 269ms
memory: 5016kb
input:
5 40 27 377494 805316 409650 555211 215919 562932 728601 882925 491459 981054 115920 400084 561128 770707 618806 738984 423273 497716 909952 570941 336586 482436 558013 483318 416358 778767 582195 135162 351591 452031 647678 929155 182083 399480 918545 401648 57249 285925 829062 728097 843359 893588...
output:
844749482389573 1 3 4 5 6 7 8 9 11 12 14 19 20 21 22 23 26 27 28 29 32 33 34 35 36 38 39 706227580053281 1 3 4 5 7 8 10 11 12 13 14 15 16 19 20 21 22 23 24 25 26 29 32 34 35 36 38 1200413036531411 1 3 4 5 6 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 34 35 36 37 38 39 40...
result:
ok Correct (5 tests)
Test #6:
score: 0
Accepted
time: 268ms
memory: 5060kb
input:
5 40 19 186606 972700 513893 732260 651137 745163 893388 575034 801995 175190 940583 725940 822306 881422 738091 350866 488466 518552 775243 213377 754121 848068 502963 89650 346047 722366 201275 21951 204639 909339 949422 143627 467989 705576 182951 395813 106964 18279 778373 776993 302086 665850 5...
output:
429855995296682 1 2 3 4 5 7 14 15 18 19 22 24 28 30 33 34 35 36 38 583568280834554 1 2 4 5 6 7 8 12 14 15 17 18 19 21 24 25 27 28 30 31 34 38 39 40 1007766487925869 1 2 3 4 5 6 7 8 9 12 13 15 18 19 20 21 22 23 24 26 27 28 30 31 33 34 36 37 38 39 40 1143756451547234 1 2 3 4 5 6 7 8 9 10 11 12 14 15 1...
result:
ok Correct (5 tests)
Test #7:
score: 0
Accepted
time: 263ms
memory: 5056kb
input:
5 40 35 70400 139398 99636 946992 123352 446578 21175 711645 112529 924825 209746 570979 82799 585318 858060 962064 109842 57887 715218 855814 578473 769882 3412 695982 757236 665966 820355 464924 539188 367331 213480 358100 716895 973989 928174 834480 675180 269133 246868 306705 686131 881928 63074...
output:
1052258845078241 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 36 37 38 39 40 225439517955660 7 13 14 16 17 18 24 26 27 28 38 39 10309247698229 34 35 867716207500786 2 4 5 6 7 8 9 10 11 12 13 14 15 16 19 20 21 23 24 25 26 27 30 31 32 34 35 36 37 38 39 16722490898...
result:
ok Correct (5 tests)
Test #8:
score: 0
Accepted
time: 269ms
memory: 4960kb
input:
5 40 35 917196 787598 241562 161724 596253 591809 704462 848256 904565 118276 515909 934518 862478 696033 940346 573946 175036 115722 580509 54434 959009 173197 948364 820814 167739 91065 958620 389398 354552 824639 996724 128070 2799 205401 229579 828645 280393 556985 233864 355601 144859 617191 75...
output:
1070384528063876 1 2 3 4 5 7 8 9 10 11 12 13 14 15 16 17 19 20 21 22 23 24 25 26 28 30 31 32 33 34 35 36 37 38 40 394240112203646 2 4 7 9 10 14 15 16 18 22 27 30 33 34 37 39 40 728666969687926 1 3 4 5 7 8 10 11 12 13 14 15 16 17 18 20 22 23 24 26 27 28 32 33 34 37 38 39 82383556555352 10 11 16 17 21...
result:
ok Correct (5 tests)
Test #9:
score: 0
Accepted
time: 269ms
memory: 4984kb
input:
5 40 11 800990 954982 827306 338773 586969 293224 869249 21864 252098 867912 747388 298056 122970 362245 22631 148145 796413 655058 483484 696871 339544 539514 411813 464144 578928 34665 577699 757688 170601 281946 260782 304859 251705 955314 974802 822810 330109 807839 627677 366814 566588 389452 9...
output:
188816088990549 1 4 12 18 19 22 24 33 35 37 40 55986183043314 11 14 16 30 31 33 282684586984324 9 14 15 16 17 20 23 26 27 30 33 37 38 40 846786488121493 1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 18 21 22 23 24 25 26 28 29 30 32 34 35 36 37 39 40 909377300034056 1 2 3 4 5 6 8 9 10 11 13 14 15 16 18 21 22 2...
result:
ok Correct (5 tests)
Test #10:
score: 0
Accepted
time: 264ms
memory: 4952kb
input:
5 40 3 203283 84680 931549 516507 59184 956956 515536 158475 562633 99047 53550 180094 384149 510644 104916 240843 861606 675894 941959 339307 720080 905145 912948 70476 990117 15264 715279 682161 23649 776938 599524 37830 537610 224411 239208 261476 898324 58692 614672 452709 987632 643215 92587 86...
output:
16250708007685 24 34 35 147504726678494 6 7 8 12 20 24 27 31 34 39 1041145136990273 1 2 3 5 6 7 8 11 12 13 14 17 18 20 21 22 23 24 25 26 27 28 29 30 31 33 34 36 37 38 39 40 365124481934200 1 2 5 6 9 12 14 18 19 20 26 28 31 34 37 38 39 15221561015297 24 30 33
result:
ok Correct (5 tests)
Test #11:
score: 0
Accepted
time: 2ms
memory: 3696kb
input:
50 8 7 563558 314099 52734 73377 332270 590552 646972 765944 98713 556129 288028 758164 572776 499897 97667 406801 801149 614476 545426 120879 38843 839594 877525 651356 8 3 226356 669424 469393 550063 173289 794466 908445 160219 504986 479445 444909 370083 264919 94919 590823 896708 51840 965987 36...
output:
36636314222837 1 2 3 4 5 6 8 10827749350481 2 3 6 6028750536179 1 3 48041933857901 1 3 5 6 7 8 625569455729 1 1750997852217 1 21861637683545 1 2 3 4 5 288208217585 1 4683255035576 2 4 13621537943579 2 3 4 912021979641 1 9666522356917 1 2 3 3977134723358 1 2 7099096890122 3 4 344454534014 1 121600836...
result:
ok Correct (50 tests)
Test #12:
score: 0
Accepted
time: 2ms
memory: 3572kb
input:
42 8 5 693258 456026 267467 101777 996002 236839 302082 557979 848349 787609 651567 981659 758174 619181 708865 991179 340484 517451 225546 463731 404475 303044 483857 24860 7 5 113145 966974 926701 814123 387762 43371 176856 424626 980651 566844 177262 357078 350814 553647 326086 25759 609908 87483...
output:
30416613337054 1 3 4 5 6 23605437783397 1 3 5 6 7 5849092179176 3 5 11261875153385 1 3 4 23602712610269 2 3 5 7 8 6679075420437 1 2 8325919927643 1 2 3 1571454158554 1 11564587559234 1 2 6 450854953666 1 4440359099257 3 4 16942435341514 1 2 3 4 5 45357060723386 1 3 4 5 7 8 6783087313137 1 2 3 913397...
result:
ok Correct (42 tests)
Test #13:
score: 0
Accepted
time: 2ms
memory: 3624kb
input:
43 6 2 918089 70120 662830 696025 354138 958971 444347 32956 299658 841774 155081 200910 388637 626360 20902 623655 336603 908094 4 1 894338 310421 883479 800116 101306 544201 539198 167785 610871 99691 313951 418576 5 1 188758 128411 394398 202942 248070 631201 818961 821071 498206 22239 12758 2280...
output:
5704610145706 2 6 1676736798926 1 1593063924998 3 14251355469449 1 2 3 4 1096252946965 1 38930442504849 1 2 4 5 6 7 6163651905025 1 2 1597770732442 1 2 16958423501362 1 2 3 4 34443636314757 1 2 3 4 5 35910186363794 1 2 3 5 8 1972461337182 1 6128116718517 1 2 3 24702844316246 1 2 5 6 4697948502254 1 ...
result:
ok Correct (43 tests)
Test #14:
score: 0
Accepted
time: 2ms
memory: 3916kb
input:
49 6 2 47788 174362 877563 168241 17868 123757 580958 343491 493795 110937 37119 979903 92533 708646 151284 689533 357439 811069 6 5 259969 255372 489810 211304 44905 681781 500671 20834 31179 919935 528424 667482 959175 993068 664424 178126 682250 671438 2 1 591222 950123 56273 893406 995519 129606...
output:
4004008941048 4 6 22743681169667 1 2 4 5 6 1806030075433 2 1327787282705 1 17236534698595 1 2 4 1598551642742 1 6865902267377 1 2 3 901648881714 1 4563161074281 3 4 34109116625025 1 3 4 5 6 7 1188113278325 1 5934299446715 1 2 3 1238991966091 1 1872644554619 4 5585267874665 1 3 1707661502193 1 786925...
result:
ok Correct (49 tests)
Test #15:
score: 0
Accepted
time: 2ms
memory: 3576kb
input:
47 6 1 732987 760106 55296 603458 200099 807044 717568 172525 205746 935599 325975 241081 203248 790931 725483 273225 378276 713360 8 2 663284 718822 614642 622493 507005 300860 868961 355383 526171 183993 261395 953387 190587 257474 621590 746342 933104 658434 382862 548657 807301 79174 576656 8015...
output:
1193207179554 5 6336627471128 1 6 2241434330645 1 2 30542757416069 2 3 5 6 7 83381369400 1 24984301717317 2 4 5 7 8 2170245857053 1 2 9681020760609 1 2 3 4 35522725800605 1 2 3 4 5 6 7 12379607136837 2 4 7 1052082860014 1 61868644715 1 4853953193194 1 2 1106819478866 1 5258583975593 2 3 383561891204...
result:
ok Correct (47 tests)
Test #16:
score: 0
Accepted
time: 2ms
memory: 3692kb
input:
44 6 5 900371 902033 232344 113358 864516 934832 891178 483060 436882 204762 208014 501575 870146 910901 337365 856918 954611 616335 3 3 66599 701457 220973 995998 450604 439125 793434 170747 983479 8 5 202292 459000 39696 97255 352240 665458 89245 394075 932702 579562 245226 134722 672736 442538 93...
output:
36667560176046 1 2 3 5 6 7896017432754 1 2 3 22426403803865 2 3 5 6 8 5551622199051 1 2 3 1454362674978 2 5001343394027 1 5 14472075282505 2 3 4 5052740551731 1 2 3 4 4257211298785 2 4 817252599090 1 13580171395470 1 3 4 5 6 18907511696804 1 2 3 5 1863566715667 1 19159953615761 2 3 4 6 1161215768297...
result:
ok Correct (44 tests)
Test #17:
score: 0
Accepted
time: 112ms
memory: 4712kb
input:
14 7 4 16 42 81 92 86 7 38 18 40 67 96 24 63 2 69 2 34 76 87 67 55 3 3 0 26 49 59 75 59 50 19 40 3 1 74 45 63 40 7 82 26 60 10 6 6 96 72 79 49 63 38 19 53 16 2 8 53 59 27 60 96 60 80 35 31 80 49 62 97 15 84 38 94 15 78 59 86 34 82 89 89 32 46 22 27 88 88 56 29 13 58 9 26 85 72 46 14 56 35 25 35 23 3...
output:
182507 2 4 5 7 48185 1 2 3 11470 1 289406 1 2 3 4 5 6 8684294 1 2 3 4 5 6 7 8 10 11 12 13 15 16 17 18 19 20 22 23 24 25 26 27 28 29 31 32 33 34 35 264653 3 6 7 9 5810787 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 495722 1 2 3 4 5 6 7 8 19533 1 14853 1 4809501 1 2 4 5 6 8 9 ...
result:
ok Correct (14 tests)
Test #18:
score: 0
Accepted
time: 102ms
memory: 4700kb
input:
9 23 9 99 87 77 0 13 29 96 12 87 99 3 6 93 74 15 61 64 33 63 57 67 94 42 18 18 67 13 78 6 72 68 15 82 11 97 34 65 64 52 68 44 34 85 53 60 75 48 31 85 65 50 60 12 11 56 81 8 76 73 30 9 7 74 16 98 12 80 7 62 13 13 32 26 29 44 22 72 16 10 75 8 46 14 63 16 11 53 22 29 18 58 91 89 75 61 69 31 83 68 19 12...
output:
1057201 1 3 5 7 8 13 15 17 20 963371 1 2 3 4 5 6 7 8 9 10 11 12 13 19685 9 146494 5 8 9 267229 8 13 28 37 4047069 1 2 3 4 10 12 15 16 17 18 20 21 22 25 27 28 29 30 31 35 6390798 1 2 3 4 5 6 7 8 9 12 14 15 17 18 19 21 22 23 24 25 26 27 28 29 30 31 32 33 2245044 1 3 5 6 7 8 9 14 15 17 18 19 20 21 22 2...
result:
ok Correct (9 tests)
Test #19:
score: -100
Runtime Error
input:
10 15 13 25 65 17 41 39 85 87 73 23 64 9 31 9 44 6 75 93 69 40 25 90 0 38 70 76 96 56 81 98 28 84 90 70 100 20 23 35 11 98 21 49 19 27 95 45 37 29 60 52 33 73 12 38 73 44 54 75 82 98 90 92 45 1 47 34 44 20 53 85 62 80 36 60 9 44 85 1 9 17 16 27 4 27 4 83 80 62 89 29 24 0 38 51 10 39 90 37 66 90 36 0...