QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#188518 | #7235. Points | ucup-team004 | WA | 265ms | 4908kb | C++20 | 3.5kb | 2023-09-25 22:20:07 | 2023-09-25 22:20:08 |
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 = [&](const Point &v) {
if (vis.count({v.x, v.y, v.z})) {
return;
}
vis.insert({v.x, v.y, 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)) {
i64 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]);
std::sort(p.begin() + l, p.begin() + r,
[&](int i, int j) {
return dot(u, a[i]) > dot(u, a[j]);
});
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3512kb
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: 0ms
memory: 3548kb
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: 247ms
memory: 4796kb
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: 251ms
memory: 4832kb
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: 254ms
memory: 4848kb
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: 262ms
memory: 4868kb
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: 242ms
memory: 4848kb
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: 265ms
memory: 4800kb
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: 247ms
memory: 4808kb
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: 248ms
memory: 4908kb
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: -100
Wrong Answer
time: 2ms
memory: 3472kb
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:
wrong answer test #36: Participant's answer is not optimal