QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#103218#441. 制作菜品bashkort100 ✓296ms12348kbC++203.3kb2023-05-04 20:05:222023-05-04 20:05:23

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-04 20:05:23]
  • 评测
  • 测评结果:100
  • 用时:296ms
  • 内存:12348kb
  • [2023-05-04 20:05:22]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

vector<array<int, 4>> easy(int m, int k, vector<int> ord, vector<int> a) {
    assert(m + 1 >= ord.size());
    set<pair<int, int>> st;
    for (int i : ord) {
        st.emplace(a[i], i);
    }

    vector<array<int, 4>> ans;

    while (ans.size() < m && !st.empty()) {
        auto [di, i] = *st.begin();
        st.erase(st.begin());

        if (di >= k) {
            ans.push_back({i + 1, k});
            if (di > k) {
                st.emplace(di - k, i);
            }
            continue;
        }

        if (st.empty()) {
            break;
        }

        auto [dj, j] = *st.rbegin();
        st.erase(prev(st.end()));

        if (di + dj < k) {
            break;
        }

        ans.push_back({i + 1, di, j + 1, k - di});

        dj -= k - di;
        if (dj > 0) {
            st.emplace(dj, j);
        }
    }

    assert(ans.size() == m);
    return ans;
}

constexpr int X = 1e6 + 7;

bitset<X * 2 + 1> B;
int par[X * 2 + 1];

void solve() {
    int n, m, k;
    cin >> n >> m >> k;

    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        b[i] = k - a[i];
    }

    vector<array<int, 4>> ans;

    if (m != n - 2) {
        vector<int> ord(n);
        iota(ord.begin(), ord.end(), 0);
        ans = easy(m, k, ord, a);
    } else {
        B.reset();
        B[X] = true;

        vector<int> o(n);
        iota(o.begin(), o.end(), 0);
        mt19937 rnd(1337);
        shuffle(o.begin(), o.end(), rnd);

        int mn = 0, mx = 0;

        for (int i : o) {
            auto nw = B;
            if (b[i] >= 0) {
                B |= B << b[i];
            } else {
                B |= B >> (-b[i]);
            }
            nw ^= B;

            for (int t = nw._Find_first(); t < nw.size(); t = nw._Find_next(t)) {
                par[t] = i;
            }
        }

        vector<int> type(n, 1);
        bool yay = false;

        if (B[X + k]) {
            int x = k;
            while (x != 0) {
                int i = par[X + x];
                type[i] = 0;
                x -= b[i];
            }

            yay = true;
        }

        if (!yay) {
            cout << "-1\n";
            return;
        }

        for (int t = 0; t < 2; ++t) {
            vector<int> ord;
            int s = 0;

            for (int i = 0; i < n; ++i) {
                if (type[i] == t) {
                    s += a[i];
                    ord.push_back(i);
                }
            }

            auto now = easy(s / k, k, ord, a);
            ans.insert(ans.end(), now.begin(), now.end());
        }
    }

    if (ans.size() != m) {
        cout << "-1\n";
    } else {
        for (auto [i, di, j, dj] : ans) {
            cout << i << " " << di;
            if (j > 0) {
                cout << " " << j << " " << dj;
            }
            cout << '\n';
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

#ifdef __APPLE__
    freopen("dish.in", "r", stdin);
    freopen("dish.out", "w", stdout);
#endif

    int test = 1;
    cin >> test;

    while (test--) {
        solve();
    }

    return 0;
}

詳細信息

Test #1:

score: 5
Accepted
time: 1ms
memory: 6408kb

input:

10
4 2 50
13 39 35 13
4 3 45
19 55 34 27
4 3 47
18 33 20 70
4 2 48
5 8 40 43
4 2 47
8 37 25 24
4 2 46
1 10 45 36
4 2 49
2 5 47 44
4 2 49
34 31 25 8
4 2 45
27 31 21 11
4 2 50
35 12 27 26

output:

-1
1 19 2 26
4 27 3 18
3 16 2 29
1 18 4 29
3 20 4 27
4 14 2 33
2 8 3 40
1 5 4 43
-1
2 10 4 36
1 1 3 45
2 5 4 44
1 2 3 47
-1
-1
-1

result:

ok OK both got answer: NYYYNYYNNN

Test #2:

score: 5
Accepted
time: 3ms
memory: 6492kb

input:

10
4 2 50
16 24 30 30
4 3 47
2 79 53 7
4 3 50
32 61 44 13
4 2 50
1 6 44 49
4 2 47
19 21 26 28
4 2 46
10 10 36 36
4 2 46
5 2 41 44
4 2 47
33 29 26 6
4 2 45
34 32 23 1
4 2 45
27 11 29 23

output:

-1
1 2 2 45
4 7 3 40
3 13 2 34
4 13 2 37
2 24 3 26
3 18 1 32
2 6 3 44
1 1 4 49
2 21 3 26
1 19 4 28
2 10 3 36
1 10 4 36
2 2 4 44
1 5 3 41
-1
-1
-1

result:

ok OK both got answer: NYYYYYYNNN

Test #3:

score: 5
Accepted
time: 5ms
memory: 6484kb

input:

10
4 2 50
30 24 22 24
4 4 49
27 2 82 85
4 3 48
25 7 58 54
4 2 49
7 2 42 47
4 2 48
24 17 29 26
4 2 47
5 2 42 45
4 2 47
1 5 46 42
4 2 49
41 27 13 17
4 2 45
32 38 1 19
4 2 48
2 37 27 30

output:

-1
2 2 4 47
1 27 3 22
4 38 3 11
3 49
2 7 3 41
3 17 4 31
4 23 1 25
2 2 4 47
1 7 3 42
-1
2 2 4 45
1 5 3 42
2 5 4 42
1 1 3 46
-1
-1
-1

result:

ok OK both got answer: NYYYNYYNNN

Test #4:

score: 5
Accepted
time: 9ms
memory: 6468kb

input:

10
10 8 5000
5342 2288 3662 4105 4769 3942 5355 3406 4746 2385
10 9 4698
1039 6862 6700 5529 5825 3904 2539 5303 3551 1030
10 10 4730
4387 531 7610 2566 236 4490 2510 8625 8084 8261
10 8 4806
1147 891 10 173 1046 1138 853 1176 11527 20487
10 8 4719
6495 10158 2542 2599 2552 2821 2521 2457 2778 2829
...

output:

-1
10 1030 2 3668
1 1039 3 3659
7 2539 5 2159
3 3041 4 1657
2 3194 8 1504
9 3551 6 1147
6 2757 4 1941
4 1931 8 2767
8 1032 5 3666
5 236 8 4494
2 531 10 4199
7 2510 9 2220
4 2566 3 2164
10 4062 9 668
8 4131 3 599
1 4387 9 343
6 4490 9 240
9 4613 3 117
3 4730
3 10 10 4796
4 173 10 4633
5 1046 10 3760
...

result:

ok OK both got answer: NYYYYYYNNY

Test #5:

score: 5
Accepted
time: 9ms
memory: 8452kb

input:

10
10 8 5000
6157 6740 2393 3458 2043 1360 6248 1866 4221 5514
10 9 4538
2843 5424 4477 3285 6508 6308 1055 2505 3471 4966
10 10 4768
7647 4253 6258 1620 1896 5150 4265 7169 3108 6314
10 8 4530
203 386 695 553 454 907 161 138 7699 25044
10 8 4749
12629 3640 2377 2953 3034 2552 2594 2539 2971 2703
10...

output:

-1
7 1055 5 3483
8 2505 6 2033
1 2843 2 1695
5 3025 10 1513
4 3285 3 1253
3 3224 6 1314
6 2961 2 1577
2 2152 9 2386
9 1085 10 3453
4 1620 1 3148
5 1896 8 2872
9 3108 10 1660
2 4253 3 515
7 4265 3 503
8 4297 3 471
1 4499 6 269
10 4654 6 114
6 4767 3 1
3 4768
5 454 9 4076
6 907 9 3623
8 138 10 4392
7 ...

result:

ok OK both got answer: NYYYNYYNNN

Test #6:

score: 5
Accepted
time: 2ms
memory: 4196kb

input:

10
500 499 5000
3843 636 8549 185 5830 892 8932 7825 5651 7620 6940 2405 7094 3940 1386 8882 8067 4484 5330 6806 6447 8253 1493 2867 4309 4942 2164 5890 4198 7743 7659 8054 8378 6352 8239 4353 7245 7315 2322 3040 5080 9262 5445 2318 3346 6831 1345 1557 1459 6674 8363 7906 5072 1 917 9381 4943 3081 5...

output:

54 1 141 4999
123 4 112 4996
210 20 348 4980
411 56 130 4944
458 60 468 4940
160 88 100 4912
71 143 262 4857
487 163 285 4837
248 180 353 4820
263 180 198 4820
4 185 221 4815
479 209 431 4791
287 311 65 4689
343 327 500 4673
390 329 467 4671
116 341 404 4659
166 408 306 4592
430 502 239 4498
164 506...

result:

ok OK both got answer: YYYYYYYYYY

Test #7:

score: 5
Accepted
time: 2ms
memory: 4256kb

input:

10
500 499 5000
6364 9285 10151 6902 4812 383 1398 4035 1971 9873 7569 5965 325 5298 1360 8638 1972 5110 4572 251 3205 9987 5918 5656 9501 10136 6777 5295 1349 9650 5545 7712 8543 5303 4221 2961 5686 5619 6996 7657 5099 4172 3229 5425 9470 4589 3669 1048 9699 8241 1300 2511 7835 7218 8167 6943 6961 ...

output:

372 57 152 4943
193 84 294 4916
255 149 267 4851
287 155 368 4845
361 211 143 4789
92 233 442 4767
120 242 138 4758
20 251 170 4749
137 257 204 4743
471 275 72 4725
265 298 3 4702
379 305 387 4695
13 325 26 4675
476 356 446 4644
237 360 348 4640
6 383 332 4617
450 383 277 4617
178 405 22 4595
312 42...

result:

ok OK both got answer: YYYYYYYYYY

Test #8:

score: 5
Accepted
time: 7ms
memory: 4292kb

input:

10
500 499 5000
3262 2165 5773 7999 8262 4733 3525 9726 2951 1150 7415 3911 8271 1083 1070 2438 5462 121 3183 3406 4427 604 9652 7737 3618 9228 586 3865 8022 5399 2492 1306 7564 8264 9304 5848 3019 2852 5597 5971 4002 3034 9882 2296 4117 974 4734 9579 1096 7917 3007 5522 8522 2682 3282 2162 1932 386...

output:

153 54 442 4946
430 63 60 4937
179 65 242 4935
213 80 301 4920
432 88 194 4912
189 92 451 4908
458 103 168 4897
347 109 291 4891
18 121 43 4879
336 145 409 4855
364 163 395 4837
461 166 109 4834
438 167 68 4833
254 206 352 4794
398 208 233 4792
351 228 92 4772
102 248 212 4752
279 292 75 4708
367 30...

result:

ok OK both got answer: YYYYYYYYYY

Test #9:

score: 5
Accepted
time: 8ms
memory: 4280kb

input:

10
500 499 5000
376 381 6759 4321 1893 4083 656 572 8961 7703 7497 2069 1181 1998 5786 6456 3949 5274 1870 1472 749 1478 8484 20 7946 3563 4574 2497 9538 6433 9457 9905 6814 6258 4268 8707 384 4925 9279 9345 2670 6818 1456 3851 8816 7242 349 2808 2558 2219 4280 3308 3697 2806 3327 1685 6369 7902 418...

output:

197 10 67 4990
24 20 65 4980
383 29 453 4971
170 31 299 4969
259 45 32 4955
92 49 360 4951
457 82 263 4918
257 100 470 4900
478 145 71 4855
462 181 143 4819
109 189 466 4811
66 208 87 4792
364 228 162 4772
230 236 235 4764
239 237 376 4763
243 245 346 4755
408 258 29 4742
47 349 248 4651
68 366 499 ...

result:

ok OK both got answer: YYYYYYYYYY

Test #10:

score: 5
Accepted
time: 18ms
memory: 8612kb

input:

10
25 23 5000
1582 1893 7547 6423 6090 3892 4873 4774 2419 2735 5981 2688 3103 6615 6641 5380 2563 5787 7635 7001 1653 7130 6048 1202 3345
25 4081 4766
1369984 261096 700757 803287 573341 1074135 738958 287371 722477 1506529 1248259 111432 430938 235065 1290857 961063 846904 1042705 718050 355187 15...

output:

1 1582 20 3418
12 2688 15 2312
10 2735 11 2265
25 3345 16 1655
20 3583 7 1417
7 3456 8 1544
8 3230 15 1770
15 2559 16 2441
16 1284 11 3716
24 1202 19 3798
21 1653 3 3347
2 1893 22 3107
9 2419 14 2581
17 2563 4 2437
13 3103 5 1897
19 3837 23 1163
6 3892 18 1108
4 3986 23 1014
23 3871 18 1129
18 3550 ...

result:

ok OK both got answer: YYYYYYYYYN

Test #11:

score: 5
Accepted
time: 16ms
memory: 6472kb

input:

10
25 1181 462
27553 24516 201 15428 23094 32388 21669 7407 32798 40696 20339 22360 33207 21199 22486 32400 30281 21768 20176 4462 2709 25794 34237 21829 6625
25 23 490
56 500 3 104 62 39 17 83 10 110 44 14 16 94 30 43 51 4 117 65 16 102 456 4806 4428
25 23 480
47 75 21 508 41 3 48 57 10 70 589 96 5...

output:

3 201 10 261
21 462
21 462
21 462
21 462
21 462
21 399 10 63
20 462
20 462
20 462
20 462
20 462
20 462
20 462
20 462
20 462
20 304 10 158
25 462
25 462
25 462
25 462
25 462
25 462
25 462
25 462
25 462
25 462
25 462
25 462
25 462
25 462
25 157 10 305
8 462
8 462
8 462
8 462
8 462
8 462
8 462
8 462
8 ...

result:

ok OK both got answer: YYYYYYYYYN

Test #12:

score: 5
Accepted
time: 12ms
memory: 6516kb

input:

10
25 1996 459
42271 3951 22551 39538 47172 12207 69249 32050 23450 71343 14663 50987 57351 29133 43127 42623 60062 37544 15504 39007 49586 17876 2088 70962 21869
25 23 492
68 65 77 77 12 8 40 58 24 93 5 46 69 1 92 48 75 56 43 44 111 3 2 4572 5627
25 23 470
496 17 88 437 56 86 66 38 86 86 92 13 100 ...

output:

23 459
23 459
23 459
23 459
23 252 10 207
2 459
2 459
2 459
2 459
2 459
2 459
2 459
2 459
2 279 10 180
6 459
6 459
6 459
6 459
6 459
6 459
6 459
6 459
6 459
6 459
6 459
6 459
6 459
6 459
6 459
6 459
6 459
6 459
6 459
6 459
6 459
6 459
6 459
6 459
6 459
6 459
6 273 24 186
11 459
11 459
11 459
11 459
...

result:

ok OK both got answer: YYYYYYYYYY

Test #13:

score: 5
Accepted
time: 20ms
memory: 6532kb

input:

10
40 2512 475
13292 14201 12975 71320 26633 55182 40472 7861 24905 21752 36640 22060 55829 23162 33190 44623 15134 24868 26316 10462 6520 35857 72022 31604 16527 10443 72278 20073 4676 30582 16987 17966 44783 29963 16708 71415 12567 57181 6699 37472
40 38 459
62 59 50 64 101 45 19 48 66 23 56 10 34...

output:

29 475
29 475
29 475
29 475
29 475
29 475
29 475
29 475
29 475
29 401 27 74
21 475
21 475
21 475
21 475
21 475
21 475
21 475
21 475
21 475
21 475
21 475
21 475
21 475
21 345 27 130
39 475
39 475
39 475
39 475
39 475
39 475
39 475
39 475
39 475
39 475
39 475
39 475
39 475
39 475
39 49 27 426
8 475
8 ...

result:

ok OK both got answer: YYYYYYYYYN

Test #14:

score: 5
Accepted
time: 27ms
memory: 8524kb

input:

10
50 2076 493
13768 16083 2191 44149 4290 40590 31917 13314 17253 29746 38642 43320 35890 11453 39167 6759 4608 7908 24128 12150 47546 11145 21662 18819 6855 1750 32550 19098 14245 39372 8714 28012 7662 10904 24369 11953 3702 8493 25267 20955 38239 16116 16483 26336 27570 7857 33095 32177 15765 943...

output:

26 493
26 493
26 493
26 271 21 222
3 493
3 493
3 493
3 493
3 219 21 274
37 493
37 493
37 493
37 493
37 493
37 493
37 493
37 251 21 242
5 493
5 493
5 493
5 493
5 493
5 493
5 493
5 493
5 346 21 147
17 493
17 493
17 493
17 493
17 493
17 493
17 493
17 493
17 493
17 171 21 322
16 493
16 493
16 493
16 493...

result:

ok OK both got answer: YYYYYYYYYY

Test #15:

score: 5
Accepted
time: 58ms
memory: 8556kb

input:

10
80 78 5000
8040 5713 8368 9134 8571 8109 7586 4125 7300 8857 8252 4188 5699 4785 6890 1459 1717 1611 4490 4584 6110 8045 3749 9170 3825 7975 5314 8649 3411 305 4924 2083 6018 3925 1850 5222 2667 69 9347 600 8926 8232 4789 5258 3649 2312 6717 5367 3923 1840 584 665 518 4333 468 4342 2941 5782 3624...

output:

55 468 62 4532
40 600 1 4400
46 2312 13 2688
13 3011 54 1989
54 2344 62 2656
62 1360 1 3640
38 69 39 4931
30 305 24 4695
53 518 4 4482
72 545 41 4455
51 584 10 4416
52 665 28 4335
66 917 5 4083
69 986 63 4014
76 1087 3 3913
16 1459 11 3541
18 1611 42 3389
17 1717 6 3283
74 1795 22 3205
50 1840 80 31...

result:

ok OK both got answer: YYYYNYYYYY

Test #16:

score: 5
Accepted
time: 61ms
memory: 8612kb

input:

10
90 88 5000
5484 8888 12 5876 2700 2940 353 5052 3730 1150 3821 2601 3969 1124 6851 5536 493 6681 3568 7776 2861 4548 2986 6888 3620 7790 9415 3136 606 6329 2623 6092 5736 2634 2487 8436 5574 2840 4007 9305 3991 7828 2425 7960 8952 9276 4015 9445 6476 7583 7739 9337 2650 1244 6744 6271 9034 6678 9...

output:

85 28 67 4972
17 493 26 4507
54 1244 55 3756
55 2988 1 2012
67 3245 1 1755
1 1717 26 3283
3 12 48 4988
60 159 27 4841
83 171 59 4829
80 315 52 4685
7 353 84 4647
79 525 40 4475
76 562 46 4438
29 606 64 4394
73 1091 88 3909
71 1100 57 3900
14 1124 45 3876
10 1150 2 3850
68 1277 66 3723
69 2098 78 290...

result:

ok OK both got answer: YYYYYYYYYY

Test #17:

score: 5
Accepted
time: 69ms
memory: 8600kb

input:

10
100 98 5000
8022 7712 6112 7663 1520 7578 2583 6276 5066 2892 9298 943 7244 2199 7090 5023 4145 2293 2574 1382 4442 5853 2144 4654 3331 2729 4068 7165 7453 7925 4978 5351 5506 959 2884 7027 8537 5467 3172 3473 8359 2340 4415 5473 4539 1375 365 8684 3668 2939 10066 8110 8792 2079 2633 1992 4807 67...

output:

46 1375 1 3625
55 2633 80 2367
26 2729 9 2271
9 2795 1 2205
1 2192 62 2808
62 1196 80 3804
66 234 70 4766
47 365 51 4635
12 943 64 4057
34 959 78 4041
96 1092 75 3908
74 1128 11 3872
84 1236 59 3764
20 1382 53 3618
5 1520 48 3480
94 1543 37 3457
97 1776 41 3224
56 1992 52 3008
88 2063 30 2937
54 207...

result:

ok OK both got answer: YYYYYYYYYN

Test #18:

score: 5
Accepted
time: 198ms
memory: 12332kb

input:

10
300 298 5000
5030 5827 7011 8862 5150 6830 4727 2114 6063 4511 4362 9088 205 3225 1864 4129 7690 7517 1429 9553 5840 1890 1254 2099 7836 7291 3302 1049 9208 4207 2303 4386 173 9314 3387 5323 6283 8114 7436 2484 2764 1937 1711 2969 5163 3575 7098 2992 1231 8527 2684 7072 556 3938 9171 8392 1368 26...

output:

249 679 55 4321
28 1049 294 3951
230 1744 200 3256
40 2484 55 2516
55 2334 294 2666
294 1828 202 3172
202 1300 200 3700
70 29 95 4971
133 52 256 4948
209 130 78 4870
244 143 296 4857
117 162 143 4838
152 171 207 4829
33 173 252 4827
259 173 100 4827
138 174 20 4826
13 205 266 4795
195 219 72 4781
71...

result:

ok OK both got answer: YYYYYYYYYY

Test #19:

score: 5
Accepted
time: 247ms
memory: 12348kb

input:

10
400 398 5000
2279 4205 8320 5468 9047 6440 1995 3019 2232 1218 9740 2414 8351 9403 6770 8485 6427 2827 5318 2800 2239 8052 101 4435 7548 1757 2323 4880 899 209 4509 3183 4414 2567 8651 3200 9007 384 6218 977 1602 5697 3391 9954 4839 10161 8177 1005 2727 3234 3804 4966 1025 3906 9401 8573 5663 146...

output:

40 977 363 4023
328 2259 363 2741
363 2180 28 2820
28 2060 226 2940
226 1846 202 3154
65 7 302 4993
87 40 394 4960
159 52 224 4948
324 59 301 4941
82 65 158 4935
23 101 152 4899
299 139 374 4861
234 146 165 4854
225 175 46 4825
30 209 72 4791
247 232 271 4768
223 233 341 4767
295 255 233 4745
191 28...

result:

ok OK both got answer: YYYYYYYYYY

Test #20:

score: 5
Accepted
time: 296ms
memory: 12332kb

input:

10
500 498 5000
9985 2503 9725 1832 2649 714 9735 4079 8786 8366 10289 598 6536 5521 1487 2592 5197 8514 9590 6334 3817 4141 4407 7125 7338 1365 6816 9153 2880 6832 1744 2229 9336 833 4061 1349 1547 3160 5428 10333 890 5081 296 7426 10602 1783 10018 5163 10297 8971 861 3478 2476 5268 10603 9814 6633...

output:

226 1559 55 3441
331 1605 55 3395
446 1861 495 3139
495 2609 55 2391
55 1376 169 3624
323 11 166 4989
265 43 161 4957
177 48 354 4952
395 59 45 4941
433 64 351 4936
481 76 98 4924
125 105 162 4895
390 125 163 4875
447 125 369 4875
300 128 437 4872
135 134 40 4866
230 137 471 4863
282 223 49 4777
400...

result:

ok OK both got answer: YYYYYYYYYY

Extra Test:

score: 0
Extra Test Passed