QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#396716#7526. Credit Cardshos_lyricAC ✓52ms23788kbC++143.8kb2024-04-23 05:05:122024-04-23 05:05:13

Judging History

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

  • [2024-04-23 05:05:13]
  • 评测
  • 测评结果:AC
  • 用时:52ms
  • 内存:23788kb
  • [2024-04-23 05:05:12]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


void exper() {
  for (int N = 4; N <= 25; N += 3) {
    // [2, N]
    vector<int> dp(1<<(N-1), -1);
    vector<int> prv(1<<(N-1), -1);
    prv.back() = -2;
    for (int p = 1<<(N-1); --p; ) if (~prv[p]) {
      const int a = 2 + (31 - __builtin_clz(p));
      // for (int b = 2; b < a; ++b) if (p & 1<<(b-2)) for (int c = 2; c < b; ++c) if (p & 1<<(c-2)) {
      for (int b = a; --b >= 2; ) if (p & 1<<(b-2)) for (int c = b; --c >= 2; ) if (p & 1<<(c-2)) {
        if (a < b + c && a*a > b*b + c*c) {
          const int pp = p ^ 1<<(a-2) ^ 1<<(b-2) ^ 1<<(c-2);
          if (chmax(dp[pp], dp[p] + 1)) {
            prv[pp] = p;
          }
        }
      }
    }
    const int pm = max_element(dp.begin(), dp.end()) - dp.begin();
    cerr << N << ": " << dp[pm] << endl;
    for (int p = pm; p < (1<<(N-1)) - 1; ) {
      const int pp = p;
      p = prv[pp];
      const int a = 2 + (31 - __builtin_clz(pp ^ p));
      const int b = 2 + (31 - __builtin_clz(pp ^ p ^ 1<<(a-2)));
      const int c = 2 + (31 - __builtin_clz(pp ^ p ^ 1<<(a-2) ^ 1<<(b-2)));
      cerr << a << " " << b << " " << c << endl;
    }
  }
}
/*
4: 0
4 3 2
7: 1
5 4 2
7 6 3
10: 2
7 6 3
8 5 4
10 9 2
13: 3
9 7 3
10 6 5
11 8 4
13 12 2
16: 4
10 9 4
11 8 5
12 7 6
14 13 3
16 15 2
19: 5
12 11 4
13 9 5
14 8 7
15 10 6
17 16 3
19 18 2
22: 6
14 11 4
15 10 6
16 9 8
17 13 5
18 12 7
20 19 3
22 21 2
25: 7
15 14 5
16 13 6
17 11 7
18 10 9
19 12 8
22 21 3
23 20 4
25 24 2
*/


/*
  a+d  , a  , c  
  a+d+1, a+1, c+1
  
  d < c
  2d vs 2c+1
  tightest: max
*/
vector<vector<Int>> solve(int N) {
  assert(N % 3 == 1);
  const int K = (N - 1) / 3;
  vector<vector<Int>> ret;
  for (Int a = N, c = K + 1; c > 1; ) {
    const Int b = sqrtl(a*a - c*c - 1);
    const Int d = a - b;
    for (Int i = 0; i < d; ++i) {
      ret.push_back({a - i, b - i, c - i});
    }
    a -= 2 * d;
    c -= d;
  }
  return ret;
}

void stress() {
  for (int N = 1; N <= 1000; N += 3) {
    const auto ans = solve(N);
    if (N <= 25) {
      cout << N << ": " << ans << endl;
    }
    for (const auto &tri : ans) {
      assert(tri[0] < tri[1] + tri[2]);
      assert(tri[0]*tri[0] > tri[1]*tri[1] + tri[2]*tri[2]);
    }
  }
}

int main() {
  // exper();
  // stress();
  
  int N;
  for (; ~scanf("%d", &N); ) {
    for (; N % 3 != 1; --N) {}
    const auto ans = solve(N);
    printf("%d\n", (int)ans.size());
    for (const auto &tri : ans) {
      printf("%lld %lld %lld\n", tri[0], tri[1], tri[2]);
    }
  }
  return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3712kb

input:

3

output:

0

result:

ok OK 0 triangles!

Test #2:

score: 0
Accepted
time: 0ms
memory: 3972kb

input:

4

output:

1
4 3 2

result:

ok OK 1 triangles!

Test #3:

score: 0
Accepted
time: 0ms
memory: 3948kb

input:

9

output:

2
7 6 3
5 4 2

result:

ok OK 2 triangles!

Test #4:

score: 0
Accepted
time: 52ms
memory: 23788kb

input:

1000000

output:

333333
1000000 942808 333334
999999 942807 333333
999998 942806 333332
999997 942805 333331
999996 942804 333330
999995 942803 333329
999994 942802 333328
999993 942801 333327
999992 942800 333326
999991 942799 333325
999990 942798 333324
999989 942797 333323
999988 942796 333322
999987 942795 33332...

result:

ok OK 333333 triangles!

Test #5:

score: 0
Accepted
time: 1ms
memory: 3884kb

input:

1

output:

0

result:

ok OK 0 triangles!

Test #6:

score: 0
Accepted
time: 1ms
memory: 3824kb

input:

2

output:

0

result:

ok OK 0 triangles!

Test #7:

score: 0
Accepted
time: 1ms
memory: 3888kb

input:

5

output:

1
4 3 2

result:

ok OK 1 triangles!

Test #8:

score: 0
Accepted
time: 0ms
memory: 3804kb

input:

6

output:

1
4 3 2

result:

ok OK 1 triangles!

Test #9:

score: 0
Accepted
time: 1ms
memory: 3820kb

input:

7

output:

2
7 6 3
5 4 2

result:

ok OK 2 triangles!

Test #10:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

8

output:

2
7 6 3
5 4 2

result:

ok OK 2 triangles!

Test #11:

score: 0
Accepted
time: 1ms
memory: 3864kb

input:

10

output:

3
10 9 4
8 7 3
6 5 2

result:

ok OK 3 triangles!

Test #12:

score: 0
Accepted
time: 25ms
memory: 14328kb

input:

621316

output:

207105
621316 585782 207106
621315 585781 207105
621314 585780 207104
621313 585779 207103
621312 585778 207102
621311 585777 207101
621310 585776 207100
621309 585775 207099
621308 585774 207098
621307 585773 207097
621306 585772 207096
621305 585771 207095
621304 585770 207094
621303 585769 207093...

result:

ok OK 207105 triangles!

Test #13:

score: 0
Accepted
time: 30ms
memory: 16504kb

input:

713171

output:

237723
713170 672382 237724
713169 672381 237723
713168 672380 237722
713167 672379 237721
713166 672378 237720
713165 672377 237719
713164 672376 237718
713163 672375 237717
713162 672374 237716
713161 672373 237715
713160 672372 237714
713159 672371 237713
713158 672370 237712
713157 672369 237711...

result:

ok OK 237723 triangles!

Test #14:

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

input:

825609

output:

275202
825607 778389 275203
825606 778388 275202
825605 778387 275201
825604 778386 275200
825603 778385 275199
825602 778384 275198
825601 778383 275197
825600 778382 275196
825599 778381 275195
825598 778380 275194
825597 778379 275193
825596 778378 275192
825595 778377 275191
825594 778376 275190...

result:

ok OK 275202 triangles!

Test #15:

score: 0
Accepted
time: 34ms
memory: 17240kb

input:

782282

output:

260760
782281 737541 260761
782280 737540 260760
782279 737539 260759
782278 737538 260758
782277 737537 260757
782276 737536 260756
782275 737535 260755
782274 737534 260754
782273 737533 260753
782272 737532 260752
782271 737531 260751
782270 737530 260750
782269 737529 260749
782268 737528 260748...

result:

ok OK 260760 triangles!

Test #16:

score: 0
Accepted
time: 9ms
memory: 6000kb

input:

148128

output:

49375
148126 139654 49376
148125 139653 49375
148124 139652 49374
148123 139651 49373
148122 139650 49372
148121 139649 49371
148120 139648 49370
148119 139647 49369
148118 139646 49368
148117 139645 49367
148116 139644 49366
148115 139643 49365
148114 139642 49364
148113 139641 49363
148112 139640 ...

result:

ok OK 49375 triangles!

Test #17:

score: 0
Accepted
time: 26ms
memory: 15680kb

input:

681282

output:

227093
681280 642316 227094
681279 642315 227093
681278 642314 227092
681277 642313 227091
681276 642312 227090
681275 642311 227089
681274 642310 227088
681273 642309 227087
681272 642308 227086
681271 642307 227085
681270 642306 227084
681269 642305 227083
681268 642304 227082
681267 642303 227081...

result:

ok OK 227093 triangles!

Test #18:

score: 0
Accepted
time: 33ms
memory: 23560kb

input:

798547

output:

266182
798547 752877 266183
798546 752876 266182
798545 752875 266181
798544 752874 266180
798543 752873 266179
798542 752872 266178
798541 752871 266177
798540 752870 266176
798539 752869 266175
798538 752868 266174
798537 752867 266173
798536 752866 266172
798535 752865 266171
798534 752864 266170...

result:

ok OK 266182 triangles!

Test #19:

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

input:

349290

output:

116429
349288 329311 116430
349287 329310 116429
349286 329309 116428
349285 329308 116427
349284 329307 116426
349283 329306 116425
349282 329305 116424
349281 329304 116423
349280 329303 116422
349279 329302 116421
349278 329301 116420
349277 329300 116419
349276 329299 116418
349275 329298 116417...

result:

ok OK 116429 triangles!

Test #20:

score: 0
Accepted
time: 18ms
memory: 9032kb

input:

317275

output:

105758
317275 299129 105759
317274 299128 105758
317273 299127 105757
317272 299126 105756
317271 299125 105755
317270 299124 105754
317269 299123 105753
317268 299122 105752
317267 299121 105751
317266 299120 105750
317265 299119 105749
317264 299118 105748
317263 299117 105747
317262 299116 105746...

result:

ok OK 105758 triangles!

Test #21:

score: 0
Accepted
time: 0ms
memory: 5824kb

input:

100000

output:

33333
100000 94280 33334
99999 94279 33333
99998 94278 33332
99997 94277 33331
99996 94276 33330
99995 94275 33329
99994 94274 33328
99993 94273 33327
99992 94272 33326
99991 94271 33325
99990 94270 33324
99989 94269 33323
99988 94268 33322
99987 94267 33321
99986 94266 33320
99985 94265 33319
99984...

result:

ok OK 33333 triangles!

Test #22:

score: 0
Accepted
time: 6ms
memory: 4736kb

input:

83568

output:

27855
83566 78786 27856
83565 78785 27855
83564 78784 27854
83563 78783 27853
83562 78782 27852
83561 78781 27851
83560 78780 27850
83559 78779 27849
83558 78778 27848
83557 78777 27847
83556 78776 27846
83555 78775 27845
83554 78774 27844
83553 78773 27843
83552 78772 27842
83551 78771 27841
83550 ...

result:

ok OK 27855 triangles!

Test #23:

score: 0
Accepted
time: 3ms
memory: 4120kb

input:

41476

output:

13825
41476 39103 13826
41475 39102 13825
41474 39101 13824
41473 39100 13823
41472 39099 13822
41471 39098 13821
41470 39097 13820
41469 39096 13819
41468 39095 13818
41467 39094 13817
41466 39093 13816
41465 39092 13815
41464 39091 13814
41463 39090 13813
41462 39089 13812
41461 39088 13811
41460 ...

result:

ok OK 13825 triangles!

Test #24:

score: 0
Accepted
time: 4ms
memory: 4764kb

input:

61028

output:

20342
61027 57536 20343
61026 57535 20342
61025 57534 20341
61024 57533 20340
61023 57532 20339
61022 57531 20338
61021 57530 20337
61020 57529 20336
61019 57528 20335
61018 57527 20334
61017 57526 20333
61016 57525 20332
61015 57524 20331
61014 57523 20330
61013 57522 20329
61012 57521 20328
61011 ...

result:

ok OK 20342 triangles!

Test #25:

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

input:

34231

output:

11410
34231 32273 11411
34230 32272 11410
34229 32271 11409
34228 32270 11408
34227 32269 11407
34226 32268 11406
34225 32267 11405
34224 32266 11404
34223 32265 11403
34222 32264 11402
34221 32263 11401
34220 32262 11400
34219 32261 11399
34218 32260 11398
34217 32259 11397
34216 32258 11396
34215 ...

result:

ok OK 11410 triangles!

Test #26:

score: 0
Accepted
time: 1ms
memory: 4140kb

input:

10000

output:

3333
10000 9427 3334
9999 9426 3333
9998 9425 3332
9997 9424 3331
9996 9423 3330
9995 9422 3329
9994 9421 3328
9993 9420 3327
9992 9419 3326
9991 9418 3325
9990 9417 3324
9989 9416 3323
9988 9415 3322
9987 9414 3321
9986 9413 3320
9985 9412 3319
9984 9411 3318
9983 9410 3317
9982 9409 3316
9981 9408...

result:

ok OK 3333 triangles!

Test #27:

score: 0
Accepted
time: 1ms
memory: 4004kb

input:

8370

output:

2789
8368 7889 2790
8367 7888 2789
8366 7887 2788
8365 7886 2787
8364 7885 2786
8363 7884 2785
8362 7883 2784
8361 7882 2783
8360 7881 2782
8359 7880 2781
8358 7879 2780
8357 7878 2779
8356 7877 2778
8355 7876 2777
8354 7875 2776
8353 7874 2775
8352 7873 2774
8351 7872 2773
8350 7871 2772
8349 7870 ...

result:

ok OK 2789 triangles!

Test #28:

score: 0
Accepted
time: 1ms
memory: 3792kb

input:

5858

output:

1952
5857 5521 1953
5856 5520 1952
5855 5519 1951
5854 5518 1950
5853 5517 1949
5852 5516 1948
5851 5515 1947
5850 5514 1946
5849 5513 1945
5848 5512 1944
5847 5511 1943
5846 5510 1942
5845 5509 1941
5844 5508 1940
5843 5507 1939
5842 5506 1938
5841 5505 1937
5840 5504 1936
5839 5503 1935
5838 5502 ...

result:

ok OK 1952 triangles!

Test #29:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

688

output:

229
688 648 230
687 647 229
686 646 228
685 645 227
684 644 226
683 643 225
682 642 224
681 641 223
680 640 222
679 639 221
678 638 220
677 637 219
676 636 218
675 635 217
674 634 216
673 633 215
672 632 214
671 631 213
670 630 212
669 629 211
668 628 210
667 627 209
666 626 208
665 625 207
664 624 ...

result:

ok OK 229 triangles!

Test #30:

score: 0
Accepted
time: 0ms
memory: 3844kb

input:

6480

output:

2159
6478 6107 2160
6477 6106 2159
6476 6105 2158
6475 6104 2157
6474 6103 2156
6473 6102 2155
6472 6101 2154
6471 6100 2153
6470 6099 2152
6469 6098 2151
6468 6097 2150
6467 6096 2149
6466 6095 2148
6465 6094 2147
6464 6093 2146
6463 6092 2145
6462 6091 2144
6461 6090 2143
6460 6089 2142
6459 6088 ...

result:

ok OK 2159 triangles!

Test #31:

score: 0
Accepted
time: 0ms
memory: 4056kb

input:

1000

output:

333
1000 942 334
999 941 333
998 940 332
997 939 331
996 938 330
995 937 329
994 936 328
993 935 327
992 934 326
991 933 325
990 932 324
989 931 323
988 930 322
987 929 321
986 928 320
985 927 319
984 926 318
983 925 317
982 924 316
981 923 315
980 922 314
979 921 313
978 920 312
977 919 311
976 918...

result:

ok OK 333 triangles!

Test #32:

score: 0
Accepted
time: 0ms
memory: 3888kb

input:

491

output:

163
490 461 164
489 460 163
488 459 162
487 458 161
486 457 160
485 456 159
484 455 158
483 454 157
482 453 156
481 452 155
480 451 154
479 450 153
478 449 152
477 448 151
476 447 150
475 446 149
474 445 148
473 444 147
472 443 146
471 442 145
470 441 144
469 440 143
468 439 142
467 438 141
466 437 ...

result:

ok OK 163 triangles!

Test #33:

score: 0
Accepted
time: 1ms
memory: 3824kb

input:

667

output:

222
667 628 223
666 627 222
665 626 221
664 625 220
663 624 219
662 623 218
661 622 217
660 621 216
659 620 215
658 619 214
657 618 213
656 617 212
655 616 211
654 615 210
653 614 209
652 613 208
651 612 207
650 611 206
649 610 205
648 609 204
647 608 203
646 607 202
645 606 201
644 605 200
643 604 ...

result:

ok OK 222 triangles!

Test #34:

score: 0
Accepted
time: 0ms
memory: 3888kb

input:

63

output:

20
61 57 21
60 56 20
59 55 19
58 54 18
53 50 17
52 49 16
51 48 15
47 44 14
46 43 13
45 42 12
41 39 11
40 38 10
37 35 9
36 34 8
33 32 7
31 30 6
29 28 5
27 26 4
25 24 3
23 22 2

result:

ok OK 20 triangles!

Test #35:

score: 0
Accepted
time: 0ms
memory: 3904kb

input:

682

output:

227
682 642 228
681 641 227
680 640 226
679 639 225
678 638 224
677 637 223
676 636 222
675 635 221
674 634 220
673 633 219
672 632 218
671 631 217
670 630 216
669 629 215
668 628 214
667 627 213
666 626 212
665 625 211
664 624 210
663 623 209
662 622 208
661 621 207
660 620 206
659 619 205
658 618 ...

result:

ok OK 227 triangles!

Test #36:

score: 0
Accepted
time: 0ms
memory: 3884kb

input:

100

output:

33
100 94 34
99 93 33
98 92 32
97 91 31
96 90 30
95 89 29
88 83 28
87 82 27
86 81 26
85 80 25
84 79 24
78 74 23
77 73 22
76 72 21
75 71 20
70 67 19
69 66 18
68 65 17
64 61 16
63 60 15
62 59 14
58 56 13
57 55 12
54 52 11
53 51 10
50 49 9
48 47 8
46 45 7
44 43 6
42 41 5
40 39 4
38 37 3
36 35 2

result:

ok OK 33 triangles!

Test #37:

score: 0
Accepted
time: 0ms
memory: 4088kb

input:

38

output:

12
37 34 13
36 33 12
35 32 11
31 29 10
30 28 9
27 25 8
26 24 7
23 22 6
21 20 5
19 18 4
17 16 3
15 14 2

result:

ok OK 12 triangles!

Test #38:

score: 0
Accepted
time: 0ms
memory: 3888kb

input:

167

output:

55
166 156 56
165 155 55
164 154 54
163 153 53
162 152 52
161 151 51
160 150 50
159 149 49
158 148 48
157 147 47
146 138 46
145 137 45
144 136 44
143 135 43
142 134 42
141 133 41
140 132 40
139 131 39
130 124 38
129 123 37
128 122 36
127 121 35
126 120 34
125 119 33
118 113 32
117 112 31
116 111 30
...

result:

ok OK 55 triangles!

Test #39:

score: 0
Accepted
time: 1ms
memory: 3940kb

input:

34

output:

11
34 31 12
33 30 11
32 29 10
28 26 9
27 25 8
24 22 7
23 21 6
20 19 5
18 17 4
16 15 3
14 13 2

result:

ok OK 11 triangles!