QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#167493 | #441. 制作菜品 | hos_lyric# | 100 ✓ | 892ms | 311812kb | C++14 | 4.0kb | 2023-09-07 15:20:06 | 2023-09-07 15:20:07 |
Judging History
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 <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")
int N, M, K;
vector<int> D;
struct Dish {
int u, v;
int x, y;
};
vector<Dish> solve(const vector<int> &us, int m) {
const int n = us.size();
vector<pair<int, int>> ps;
for (const int u : us) {
ps.emplace_back(D[u], u);
}
vector<Dish> ans(m);
for (int i = 0; i < m; ++i) {
int remain = 0;
int jm = -1;
for (int j = 0; j < n; ++j) if (ps[j].first > 0) {
++remain;
if (!~jm || ps[jm].first < ps[j].first) {
jm = j;
}
}
assert(m - i >= remain - 1);
if (m - i > remain - 1 && ps[jm].first >= K) {
ans[i] = Dish{ps[jm].second, -1, K, 0};
ps[jm].first -= K;
} else {
for (int j = 0; j < n; ++j) if (jm != j && ps[j].first > 0) {
if (ps[jm].first + ps[j].first >= K && ps[j].first < K) {
const int y = ps[j].first;
ans[i] = Dish{ps[jm].second, ps[j].second, K - y, y};
ps[jm].first -= (K - y);
ps[j].first -= y;
goto found;
}
}
assert(false);
found:{}
}
}
return ans;
}
bitset<5'000'010> dp[510];
int main() {
for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
scanf("%d%d%d", &N, &M, &K);
D.resize(N);
for (int u = 0; u < N; ++u) {
scanf("%d", &D[u]);
}
cerr<<"N = "<<N<<", M = "<<M<<endl;
vector<Dish> ans;
if (M == N - 2) {
for (int u = 0; u <= N; ++u) {
dp[u].reset();
}
dp[N].set(N * K);
for (int u = N; --u >= 0; ) {
const int d = D[u] - K;
if (d >= 0) {
dp[u] = dp[u + 1] | dp[u + 1] << d;
} else {
dp[u] = dp[u + 1] | dp[u + 1] >> -d;
}
}
if (dp[0][N * K - K]) {
int t = N * K - K;
vector<int> uss[2];
for (int u = 0; u < N; ++u) {
assert(dp[u][t]);
if (dp[u + 1][t]) {
uss[0].push_back(u);
} else {
uss[1].push_back(u);
t -= (D[u] - K);
}
}
assert(t == N * K);
for (int h = 0; h < 2; ++h) {
const auto res = solve(uss[h], (int)uss[h].size() - 1);
ans.insert(ans.end(), res.begin(), res.end());
}
}
} else {
vector<int> us(N);
for (int u = 0; u < N; ++u) {
us[u] = u;
}
ans = solve(us, M);
}
if (!ans.empty()) {
assert((int)ans.size() == M);
for (const auto &dish : ans) {
if (!~dish.v) {
printf("%d %d\n", dish.u + 1, dish.x);
} else {
printf("%d %d %d %d\n", dish.u + 1, dish.x, dish.v + 1, dish.y);
}
}
} else {
puts("-1");
}
}
#ifndef LOCAL
break;
#endif
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 6ms
memory: 8576kb
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 2 26 1 19 3 16 2 29 4 27 3 18 4 29 1 18 4 14 2 33 4 27 3 20 4 43 1 5 3 40 2 8 -1 3 45 1 1 4 36 2 10 3 47 1 2 4 44 2 5 -1 -1 -1
result:
ok OK both got answer: NYYYNYYNNN
Test #2:
score: 5
Accepted
time: 5ms
memory: 8492kb
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 2 45 1 2 3 13 2 34 3 40 4 7 2 18 1 32 3 7 2 43 3 37 4 13 4 49 1 1 3 44 2 6 4 28 1 19 3 26 2 21 3 36 1 10 4 36 2 10 3 41 1 5 4 44 2 2 -1 -1 -1
result:
ok OK both got answer: NYYYYYYNNN
Test #3:
score: 5
Accepted
time: 1ms
memory: 9820kb
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 4 49 3 22 1 27 3 47 2 2 4 36 3 13 3 23 1 25 4 41 2 7 3 35 4 13 3 42 1 7 4 47 2 2 -1 3 42 1 5 4 45 2 2 3 46 1 1 4 42 2 5 -1 -1 -1
result:
ok OK both got answer: NYYYNYYNNN
Test #4:
score: 5
Accepted
time: 18ms
memory: 12928kb
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 2 3659 1 1039 3 1495 2 3203 5 794 6 3904 4 2159 7 2539 8 1328 4 3370 3 723 8 3975 5 216 3 4482 5 1147 9 3551 5 3668 10 1030 8 4730 10 343 1 4387 9 4199 2 531 10 2164 4 2566 3 4494 5 236 10 1614 3 3116 6 2220 7 2510 10 2460 6 2270 8 845 9 3885 8 3050 10 1680 9 3659 1 1147 9 3915 2 891 9 3953 7 853...
result:
ok OK both got answer: NYYYYYYNNY
Test #5:
score: 5
Accepted
time: 17ms
memory: 13296kb
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 5 1695 1 2843 6 61 3 4477 6 1253 4 3285 2 3483 7 1055 6 2597 2 1941 10 2141 6 2397 5 2033 8 2505 9 1758 5 2780 10 2825 9 1713 1 4768 8 1889 1 2879 10 515 2 4253 3 3148 4 1620 10 1658 3 3110 8 2872 5 1896 6 503 7 4265 6 2360 8 2408 10 2481 6 2287 9 3108 10 1660 10 4327 1 203 10 4144 2 386 10 3835 ...
result:
ok OK both got answer: NYYYNYYNNN
Test #6:
score: 5
Accepted
time: 7ms
memory: 4924kb
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:
141 1157 1 3843 112 4364 2 636 348 4815 4 185 130 4108 6 892 468 2595 12 2405 100 1060 14 3940 262 3614 15 1386 285 516 18 4484 353 3507 23 1493 198 2133 24 2867 221 691 25 4309 431 58 26 4942 65 2836 27 2164 500 802 29 4198 431 647 36 4353 467 2678 39 2322 404 1960 40 3040 306 2682 44 2318 239 1654...
result:
ok OK both got answer: YYYYYYYYYY
Test #7:
score: 5
Accepted
time: 7ms
memory: 4884kb
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:
152 188 5 4812 267 4617 6 383 294 3602 7 1398 368 965 8 4035 143 3029 9 1971 442 4675 13 325 138 3640 15 1360 170 3028 17 1972 204 428 19 4572 152 4749 20 251 72 1795 21 3205 3 3651 29 1349 387 779 35 4221 26 2039 36 2961 332 828 42 4172 348 1771 43 3229 446 411 46 4589 277 1331 47 3669 22 3952 48 1...
result:
ok OK both got answer: YYYYYYYYYY
Test #8:
score: 5
Accepted
time: 38ms
memory: 4912kb
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:
442 1738 1 3262 60 2835 2 2165 242 267 6 4733 301 1475 7 3525 194 2049 9 2951 451 3850 10 1150 168 1089 12 3911 291 3917 14 1083 43 3930 15 1070 409 2562 16 2438 395 4879 18 121 109 1817 19 3183 68 1594 20 3406 352 573 21 4427 92 4396 22 604 233 1382 25 3618 212 4414 27 586 75 1135 28 3865 8 2508 31...
result:
ok OK both got answer: YYYYYYYYYY
Test #9:
score: 5
Accepted
time: 22ms
memory: 4960kb
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:
67 4624 1 376 65 4619 2 381 453 679 4 4321 299 3107 5 1893 32 917 6 4083 360 4344 7 656 263 4428 8 572 470 2931 12 2069 71 3819 13 1181 143 3002 14 1998 466 1051 17 3949 87 3130 19 1870 162 3528 20 1472 235 4251 21 749 376 3522 22 1478 346 4980 24 20 29 1437 26 3563 248 426 27 4574 499 2503 28 2497 ...
result:
ok OK both got answer: YYYYYYYYYY
Test #10:
score: 5
Accepted
time: 37ms
memory: 21624kb
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:
19 3418 1 1582 3 3107 2 1893 22 560 3 4440 20 1108 6 3892 14 127 7 4873 22 226 8 4774 14 2581 9 2419 4 2265 10 2735 22 842 4 4158 5 1897 13 3103 20 807 5 4193 22 1093 14 3907 16 2437 17 2563 20 2057 16 2943 22 783 19 4217 22 1971 20 3029 25 3345 22 1655 15 2312 12 2688 23 671 15 4329 11 3347 21 1653...
result:
ok OK both got answer: YYYYYYYYYN
Test #11:
score: 5
Accepted
time: 38ms
memory: 22328kb
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:
10 462 10 462 10 462 10 462 10 462 10 462 10 462 10 462 10 462 10 462 10 462 10 462 10 462 10 462 23 462 10 462 23 462 10 462 23 462 10 462 13 462 23 462 10 462 9 462 13 462 16 462 23 462 6 462 10 462 9 462 13 462 16 462 23 462 6 462 10 462 9 462 13 462 16 462 23 462 6 462 10 462 9 462 13 462 16 462...
result:
ok OK both got answer: YYYYYYYYYN
Test #12:
score: 5
Accepted
time: 44ms
memory: 22608kb
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:
10 459 24 459 10 459 24 459 10 459 24 459 10 459 24 459 10 459 7 459 24 459 10 459 7 459 24 459 10 459 7 459 24 459 10 459 7 459 24 459 10 459 7 459 24 459 10 459 7 459 24 459 10 459 7 459 24 459 10 459 7 459 24 459 10 459 7 459 24 459 10 459 7 459 24 459 10 459 7 459 24 459 10 459 7 459 24 459 10 4...
result:
ok OK both got answer: YYYYYYYYYY
Test #13:
score: 5
Accepted
time: 69ms
memory: 30712kb
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:
27 475 23 475 27 475 23 475 36 475 27 475 4 475 23 475 36 475 27 475 4 475 23 475 36 475 27 475 4 475 23 475 36 475 27 475 4 475 23 475 36 475 27 475 4 475 23 475 36 475 27 475 4 475 23 475 36 475 27 475 4 475 23 475 36 475 27 475 4 475 23 475 36 475 27 475 4 475 23 475 36 475 27 475 4 475 23 475 36...
result:
ok OK both got answer: YYYYYYYYYN
Test #14:
score: 5
Accepted
time: 97ms
memory: 37060kb
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:
21 493 21 493 21 493 21 493 21 493 21 493 21 493 4 493 21 493 4 493 21 493 12 493 4 493 21 493 12 493 4 493 21 493 12 493 4 493 21 493 12 493 4 493 21 493 12 493 4 493 21 493 12 493 4 493 21 493 6 493 12 493 4 493 21 493 6 493 12 493 4 493 21 493 6 493 12 493 30 493 4 493 15 493 21 493 6 493 12 493 ...
result:
ok OK both got answer: YYYYYYYYYY
Test #15:
score: 5
Accepted
time: 135ms
memory: 56300kb
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:
39 875 8 4125 24 812 12 4188 4 215 14 4785 41 3541 16 1459 4 3283 17 1717 10 3389 18 1611 28 510 19 4490 5 416 20 4584 62 1251 23 3749 39 1175 25 3825 63 1589 29 3411 3 4695 30 305 24 1327 3 3673 11 76 31 4924 42 2917 32 2083 11 1075 34 3925 5 3150 35 1850 28 2333 37 2667 6 4931 38 69 22 1822 6 3178...
result:
ok OK both got answer: YYYYNYYYYY
Test #16:
score: 5
Accepted
time: 159ms
memory: 60696kb
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:
48 4988 3 12 27 2300 5 2700 59 2060 6 2940 52 4647 7 353 84 1270 9 3730 40 3850 10 1150 46 1179 11 3821 64 2399 12 2601 57 1031 13 3969 45 3876 14 1124 2 4507 17 493 66 619 2 4381 78 1432 19 3568 36 2139 21 2861 82 452 22 4548 67 2014 23 2986 66 1380 25 3620 46 1864 28 3136 84 4394 29 606 57 2377 31...
result:
ok OK both got answer: YYYYYYYYYY
Test #17:
score: 5
Accepted
time: 181ms
memory: 66804kb
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:
70 3480 5 1520 51 2417 7 2583 64 2108 10 2892 78 4057 12 943 75 2801 14 2199 11 855 17 4145 59 2707 18 2293 53 2426 19 2574 48 3618 20 1382 37 558 21 4442 11 2856 23 2144 41 346 24 4654 52 1669 25 3331 1 2271 26 2729 41 932 27 4068 37 22 31 4978 37 4041 34 959 30 2116 35 2884 64 1084 37 3916 92 1828...
result:
ok OK both got answer: YYYYYYYYYN
Test #18:
score: 5
Accepted
time: 527ms
memory: 189784kb
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:
95 273 7 4727 256 2886 8 2114 78 489 10 4511 296 638 11 4362 143 4795 13 205 207 1775 14 3225 252 3136 15 1864 100 871 16 4129 95 3571 19 1429 20 3110 22 1890 266 3746 23 1254 72 2901 24 2099 59 1698 27 3302 34 3951 28 1049 264 793 30 4207 140 2697 31 2303 122 614 32 4386 115 4827 33 173 150 1613 35...
result:
ok OK both got answer: YYYYYYYYYY
Test #19:
score: 5
Accepted
time: 696ms
memory: 250576kb
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:
302 2721 1 2279 394 795 2 4205 224 3005 7 1995 301 1981 8 3019 158 2768 9 2232 152 3782 10 1218 374 2586 12 2414 165 2173 18 2827 46 2200 20 2800 72 2761 21 2239 271 4899 23 101 341 565 24 4435 233 3243 26 1757 248 2677 27 2323 336 120 28 4880 71 4101 29 899 44 4791 30 209 389 491 31 4509 336 1817 3...
result:
ok OK both got answer: YYYYYYYYYY
Test #20:
score: 5
Accepted
time: 892ms
memory: 311812kb
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:
166 2497 2 2503 161 3168 4 1832 354 2351 5 2649 55 4286 6 714 45 921 8 4079 351 4402 12 598 98 3513 15 1487 162 2408 16 2592 163 1183 21 3817 369 859 22 4141 437 593 23 4407 40 3635 26 1365 471 2120 29 2880 49 3256 31 1744 11 2771 32 2229 380 4167 34 833 297 939 35 4061 458 3651 36 1349 413 3453 37 ...
result:
ok OK both got answer: YYYYYYYYYY
Extra Test:
score: 0
Extra Test Passed