QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#565243#9316. BoxesAfterlifeTL 116ms4036kbC++172.4kb2024-09-15 20:43:342024-09-15 20:43:36

Judging History

你现在查看的是最新测评结果

  • [2024-09-15 20:43:36]
  • 评测
  • 测评结果:TL
  • 用时:116ms
  • 内存:4036kb
  • [2024-09-15 20:43:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using db = __int128;
using T = db;
struct P {
  T x, y, z;
  explicit P(T x = 0, T y = 0, T z = 0) : x(x), y(y), z(z) {}
  T dot(P p) { return x * p.x + y * p.y + z * p.z; }
  P cross(P p) { return P(y * p.z - z * p.y, z * p.x - x * p.z, x * p.y - y * p.x); }
  P operator-(P p) { return P(x - p.x, y - p.y, z - p.z); }
//   db length() { return sqrt(x * x + y * y + z * z); }
//   friend ostream& operator<<(ostream& os, P p) { return os << "(" << p.x << ", " << p.y << ", " << p.z << ")"; }
};
const int L = 1e9;
vector<tuple<int, int, int>> hull(vector<P> p, T eps = 1e-9) {
    for(auto &[x, y, z] : p)
        x += L, y += L, z += L;
  vector<tuple<int, int, int>> res;
  if(p.size() < 3)
    return res;
  res.emplace_back(0, 1, 2);
  res.emplace_back(0, 2, 1);
  for (int i = 3; i < p.size(); i += 1) {
    vector<tuple<int, int, int>> nxt;
    set<pair<int, int>> edge;
    for (auto [a, b, c] : res) {
      T prod = (p[b] - p[a]).cross(p[c] - p[a]).dot(p[i] - p[a]);
      if (prod > 0) {
        edge.emplace(a, b);
        edge.emplace(b, c);
        edge.emplace(c, a);
      } else
        nxt.emplace_back(a, b, c);
    }
    for (auto [x, y] : edge) {
      if (edge.find({y, x})!=edge.end()) continue;
      nxt.emplace_back(x, y, i);
    }
    res.swap(nxt);
  }
  return res;
}
db volume(vector<P> p, vector<tuple<int, int, int>> f) {
  db res = 0;
  for (auto [a, b, c] : f) res += p[a].cross(p[b]).dot(p[c]);
  return  res;
}

void output(db x) {
    if(x < 10) {
        cout << (int)x;
        return;
    }
    output(x / 10);
    cout << (int) (x % 10);
}

int main() {
    int T;
    cin >> T;
    while(T--) {
        int n;
        cin >> n;
        vector<P> v(n);
        for(auto &[x, y, z] : v) {
            long long a, b, c;
            cin >> a >> b >> c;
            x = a, y = b, z = c;
        }
        db ans = 0;
        while(v.size() > 3) {
            auto h = hull(v);
            ans += volume(v, h);
            vector<int> use(v.size());
            for(auto [x, y, z] : h)
                use[x] = use[y] = use[z] = 1;
            vector<P> nv;
            for(int i = 0; i < v.size(); i += 1)
                if(!use[i])
                    nv.push_back(v[i]);
            v.swap(nv);
        }

        output(ans);
        cout << "\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3564kb

input:

2
4
0 0 1
0 0 2
0 1 1
1 1 1
10
2 6 3
2 9 0
2 1 0
3 7 3
0 5 6
10 9 2
4 4 2
8 5 2
4 6 9
6 7 5

output:

1
943

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 11ms
memory: 3868kb

input:

30
100
214848 13593 883915
404922 704679 762266
19696 348707 172137
204169 674312 980107
159743 683657 537795
913278 244484 331997
342255 150373 745862
822992 993127 812010
78019 523301 874868
508779 130959 577626
506563 15210 31018
302821 671498 135922
379735 258803 474373
387144 676958 499943
9009...

output:

8466306477510658674
7272556711339503943
7635348833914404146
8107228712222480162
8154398837331856360
7551703717471512369
8340343101157128252
7911868248459799324
7911957494280349996
8295429352750849603
8170150524727285883
7448641514858636645
8373196774630538132
7404986332777191754
7496214926512003280
...

result:

ok 30 lines

Test #3:

score: 0
Accepted
time: 2ms
memory: 3872kb

input:

300
10
284000 364959 249145
243447 261451 165064
884086 450907 263262
986606 115922 516435
550174 625062 491782
992985 764800 854837
992741 919628 758329
114851 373304 743149
236804 572126 522753
694056 863964 768484
10
328584 59621 865079
133943 928163 534857
746608 698892 195503
199343 568337 4820...

output:

803077918387863438
484728351097401010
1106436691630702280
544591678232219117
1068791025597242587
930320279051363466
977769839732812040
699051820151945692
1140525392772278038
1116781785107680980
844917700022644714
672066651386061967
638048751063849731
1258576451479348061
476673417837522259
8473170752...

result:

ok 300 lines

Test #4:

score: 0
Accepted
time: 116ms
memory: 4036kb

input:

1
3000
413652 522034 362874
161444 14592 423619
276585 592939 402025
969689 188554 136993
462321 11911 652603
155677 401331 635931
339965 202216 204346
992462 357822 565008
886658 168024 940016
767608 638795 810396
137017 720592 591380
131999 195424 726856
127795 754489 391676
201652 890036 283312
2...

output:

60273580163282897867

result:

ok single line: '60273580163282897867'

Test #5:

score: 0
Accepted
time: 39ms
memory: 3832kb

input:

3
1000
789847 633929 843311
151652 321247 368028
474261 971864 121395
276634 985203 701635
513707 455226 814706
268852 415657 58444
987338 896126 263240
299951 797298 467241
590635 66549 583890
167580 143498 207823
51652 874838 958088
384543 202601 354015
949301 50276 331784
786780 359270 507104
100...

output:

32630943894075643280
34329272009845651025
31688176605328214457

result:

ok 3 lines

Test #6:

score: -100
Time Limit Exceeded

input:

1
3000
523975 470644 532609
494477 538338 531617
478234 504027 544833
461636 519091 525762
465935 471859 476600
548753 495050 490073
472196 526755 531796
527926 514663 538795
487358 538942 471301
473223 533323 525932
529927 539631 505805
549573 493842 502137
451275 508234 507619
490260 486044 547014...

output:


result: