QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#597691 | #6339. Cookies | Dimash# | 0 | 2ms | 4728kb | C++17 | 1.7kb | 2024-09-28 18:27:06 | 2024-09-28 18:27:06 |
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 12, MOD = (int)1e9 + 7;
int n, m, b[N];
vector<pair<int,int>> a;
int res = -1;
vector<vector<int>> cur, ans;
void go(vector<pair<int, int>> x, int it) {
sort(x.begin(), x.end());
reverse(x.begin(), x.end());
while(!x.empty() && x.back().first == 0) {
x.pop_back();
}
if(x.empty()) {
if(res == -1 || res > (int)cur.size()) {
res = (int)cur.size();
ans = cur;
}
return;
}
for(int i = it; i >= 1; i--) {
if(x.size() < b[i]) continue;
int f = x[b[i] - 1].first;
vector<int> t;
for(int j = 0; j < b[i]; j++) {
t.push_back(x[j].second);
x[j].first-=f;
}
for(int j = 0;j < f; j++) cur.push_back(t);
go(x, i);
for(int j = 0;j < f; j++)cur.pop_back();
for(int j = 0; j < b[i]; j++) {
x[j].first+=f;
}
}
}
void test() {
cin >> n;
for(int i = 1; i <= n; i++) {
int x;
cin >> x;
a.push_back({x, i});
}
cin >> m;
for(int i = 1;i <= m; i++) {
cin >> b[i];
}
go(a, m);
if(res == -1) {
cout << -1 << '\n';
return;
}
cout << res << '\n';
for(auto i:ans) {
cout << (int)i.size() << ' ';
for(int j:i) {
cout << j << ' ';
}
cout << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--)
test();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 6
Accepted
time: 0ms
memory: 3576kb
input:
1 1 1 1
output:
1 1 1
result:
ok good!
Test #2:
score: 6
Accepted
time: 0ms
memory: 3516kb
input:
2 1 1 1 1
output:
2 1 2 1 1
result:
ok good!
Test #3:
score: 6
Accepted
time: 0ms
memory: 3516kb
input:
2 1 1 1 2
output:
1 2 2 1
result:
ok good!
Test #4:
score: 6
Accepted
time: 0ms
memory: 3796kb
input:
2 1 1 2 1 2
output:
1 2 2 1
result:
ok good!
Test #5:
score: 6
Accepted
time: 0ms
memory: 3604kb
input:
4 1 1 1 1 2 2 3
output:
2 2 4 3 2 2 1
result:
ok good!
Test #6:
score: 6
Accepted
time: 0ms
memory: 3556kb
input:
8 1 1 1 1 1 1 1 1 3 1 4 5
output:
2 4 8 7 6 5 4 4 3 2 1
result:
ok good!
Test #7:
score: 6
Accepted
time: 2ms
memory: 4704kb
input:
500 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
500 1 500 1 499 1 498 1 497 1 496 1 495 1 494 1 493 1 492 1 491 1 490 1 489 1 488 1 487 1 486 1 485 1 484 1 483 1 482 1 481 1 480 1 479 1 478 1 477 1 476 1 475 1 474 1 473 1 472 1 471 1 470 1 469 1 468 1 467 1 466 1 465 1 464 1 463 1 462 1 461 1 460 1 459 1 ...
result:
ok good!
Test #8:
score: 6
Accepted
time: 0ms
memory: 3628kb
input:
500 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
1 500 500 499 498 497 496 495 494 493 492 491 490 489 488 487 486 485 484 483 482 481 480 479 478 477 476 475 474 473 472 471 470 469 468 467 466 465 464 463 462 461 460 459 458 457 456 455 454 453 452 451 450 449 448 447 446 445 444 443 442 441 440 439 438 437 436 435 434 433 432 431 430 429 428 42...
result:
ok good!
Test #9:
score: 0
Time Limit Exceeded
input:
500 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
result:
Subtask #2:
score: 0
Wrong Answer
Test #28:
score: 7
Accepted
time: 0ms
memory: 3568kb
input:
1 15 1 1
output:
15 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
result:
ok good!
Test #29:
score: 7
Accepted
time: 0ms
memory: 3856kb
input:
1 500 1 1
output:
500 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
result:
ok good!
Test #30:
score: 7
Accepted
time: 1ms
memory: 4012kb
input:
1 3000 1 1
output:
3000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok good!
Test #31:
score: 7
Accepted
time: 0ms
memory: 4728kb
input:
1 15000 1 1
output:
15000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok good!
Test #32:
score: 7
Accepted
time: 0ms
memory: 3868kb
input:
2 2 1 1 1
output:
3 1 1 1 1 1 2
result:
ok good!
Test #33:
score: 7
Accepted
time: 0ms
memory: 3564kb
input:
2 1 2 1 2
output:
-1
result:
ok no solution
Test #34:
score: 7
Accepted
time: 0ms
memory: 3572kb
input:
3 1 2 3 1 2
output:
3 2 3 2 2 3 2 2 3 1
result:
ok good!
Test #35:
score: 7
Accepted
time: 0ms
memory: 3512kb
input:
3 3 2 1 1 3
output:
-1
result:
ok no solution
Test #36:
score: 0
Wrong Answer
time: 0ms
memory: 3628kb
input:
3 2 2 2 1 2
output:
-1
result:
wrong answer you didn't find a solution but jury did
Subtask #3:
score: 0
Wrong Answer
Test #45:
score: 12
Accepted
time: 0ms
memory: 3572kb
input:
2 7 8 2 1 2
output:
8 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 1 2
result:
ok good!
Test #46:
score: 0
Wrong Answer
time: 0ms
memory: 3632kb
input:
3 5 4 6 2 2 3
output:
-1
result:
wrong answer you didn't find a solution but jury did
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%