QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#697841 | #9178. All-You-Can-Eat | ucup-team4975 | WA | 43ms | 3960kb | C++23 | 3.5kb | 2024-11-01 16:00:48 | 2024-11-01 16:00:49 |
Judging History
answer
#define LOCAL
#include <bits/stdc++.h>
#define fir first
#define sec second
#define el '\n'
#ifdef LOCAL
#define FINISH cerr << "FINISH" << endl;
#else
#define FINISH ;
#endif
#ifdef LOCAL
#define debug(x) cerr << setw(4) << #x << " == " << x << endl
#else
#define debug(x)
#endif
#ifdef LOCAL
#define debugv(x) \
cerr << setw(4) << #x << ":: "; \
for (auto i : x) \
cerr << i << " "; \
cerr << endl
#else
#define debugv(x)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
ostream& operator<<(ostream& out, PII& x)
{
out << x.fir << " " << x.sec << endl;
return out;
}
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const int N = 200020;
void solve()
{
int n, cnt = 0, flag = 0, sum = 0;
cin >> n;
vector<int> a(n + 1);
vector<int> vis(n + 1, 0);
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (flag || a[i] > 1000 || a[i] == 0) {
cout << "0\nIGNORE" << endl;
continue;
}
if (a[i] >= 600) {
cout << cnt << " ";
for (int j = 1; j < i; j++) {
if (vis[j] == 1) {
vis[j] = 0;
cout << j << " ";
}
}
cout << endl;
cout << "TAKE" << endl;
vis[i] = 1, flag = 1, cnt = 1;
sum = a[i];
continue;
}
if (sum + a[i] > 1000) {
if (cnt == 1) {
int pl;
for (int j = 1; j < i; j++) {
if (vis[j] == 1) {
pl = j;
break;
}
}
if (a[pl] < a[i]) {
cout << "0\nIGNORE" << endl;
}
else {
cout << "1 " << pl << endl;
vis[pl] = 0, vis[i] = 1, sum = a[i];
cout << "TAKE" << endl;
}
}
else {
assert(sum < 600);
vector<int> las(1010, 0), dp(1010, 0);
vector<int> ans;
dp[a[i]] = 1;
for (int j = 1; j < i; j++) {
if (vis[j] == 0)
continue;
for (int k = 1000 - a[j]; k >= 0; k--) {
if (!dp[k])
continue;
dp[k + a[j]] = 1;
las[k + a[j]] = j;
}
}
int st = 0;
for (int j = 1000; j >= 0; j--) {
if (dp[j] == 1) {
st = j;
break;
}
}
/*cout << "DEBUG:: " << endl;
cout << sum << " " << st << endl;
for (int j = 1; j <= i; j++) {
if (vis[j])
cout << j << " " << a[j] << endl;
}*/
if (st < 600) {
int pl = 0;
for (int j = 1; j < i; j++) {
if (vis[j] && a[j] > a[pl]) {
pl = j;
}
if (a[pl] < a[i]) {
vis[i] = 0;
cout << "0\nIGNORE" << endl;
}
else {
vis[i] = 1;
cout << "1 " << pl << endl;
vis[pl] = 0, vis[i] = 1, sum = sum - a[pl] + a[i];
cout << "TAKE" << endl;
}
}
continue;
}
las[a[i]] = i;
flag = 1, vis[i] = 1;
while (st) {
ans.push_back(las[st]);
st = st - a[las[st]];
}
for (auto x : ans) {
vis[x]++;
}
int tmp = 0;
assert(vis[i] == 2);
for (int j = 1; j <= i; j++) {
if (vis[j] == 1)
tmp++;
}
cout << tmp << " ";
for (int j = 1; j <= i; j++) {
if (vis[j] == 1)
cout << j << " ";
}
cout << "\nTAKE" << endl;
}
}
else if (sum + a[i] >= 600) {
sum += a[i];
vis[i] = 1;
flag = 1;
cnt++;
cout << "0\nTAKE" << endl;
}
else {
sum += a[i];
vis[i] = 1;
cnt++;
cout << "0\nTAKE" << endl;
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3624kb
input:
1 5 10 13 450 585 465
output:
0 TAKE 0 TAKE 0 TAKE 1 3 TAKE 0 IGNORE
result:
ok OK, worst = 0.648188 (1 test case)
Test #2:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
1 1 100
output:
0 TAKE
result:
ok OK, worst = 1.000000 (1 test case)
Test #3:
score: 0
Accepted
time: 10ms
memory: 3880kb
input:
2000 5 535 529 536 588 558 5 515 525 599 507 549 5 561 567 504 557 596 5 592 503 549 549 536 5 590 572 589 540 544 5 524 553 545 555 543 5 523 571 577 506 594 5 519 527 521 587 539 5 561 569 573 552 587 5 571 515 585 525 589 5 512 572 565 516 527 5 573 579 564 514 557 5 518 595 509 518 549 5 549 541...
output:
0 TAKE 1 1 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 0 TAKE 0 IGNORE 0 IGNORE 1 1 TAKE 0 IGNORE 0 TAKE 0 IGNORE 1 1 TAKE 0 IGNORE 0 IGNORE 0 TAKE 1 1 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 0 TAKE 1 1 TAKE 0 IGNORE 1 2 TAKE 0 IGNORE 0 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 TAKE 0 IGNORE 0 IGNORE 1 1 TAKE 0 IGNORE...
result:
ok OK, worst = 0.836394 (2000 test cases)
Test #4:
score: 0
Accepted
time: 8ms
memory: 3844kb
input:
500 20 535 529 536 588 558 515 525 599 507 549 561 567 504 557 596 592 503 549 549 536 20 590 572 589 540 544 524 553 545 555 543 523 571 577 506 594 519 527 521 587 539 20 561 569 573 552 587 571 515 585 525 589 512 572 565 516 527 573 579 564 514 557 20 518 595 509 518 549 549 541 580 535 531 540 ...
output:
0 TAKE 1 1 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 1 2 TAKE 0 IGNORE 0 IGNORE 1 6 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 1 9 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 1 13 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 0 TAKE 1 1 TAKE 0 IGNORE 1 2 TAKE 0 IGNORE 1 4 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 1 6 TAKE 0 IGNORE 0 IGNORE 1 11 T...
result:
ok OK, worst = 0.836394 (500 test cases)
Test #5:
score: 0
Accepted
time: 4ms
memory: 3584kb
input:
200 50 535 529 536 588 558 515 525 599 507 549 561 567 504 557 596 592 503 549 549 536 590 572 589 540 544 524 553 545 555 543 523 571 577 506 594 519 527 521 587 539 561 569 573 552 587 571 515 585 525 589 50 512 572 565 516 527 573 579 564 514 557 518 595 509 518 549 549 541 580 535 531 540 596 51...
output:
0 TAKE 1 1 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 1 2 TAKE 0 IGNORE 0 IGNORE 1 6 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 1 9 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 1 13 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IG...
result:
ok OK, worst = 0.836394 (200 test cases)
Test #6:
score: 0
Accepted
time: 12ms
memory: 3840kb
input:
100 100 535 529 536 588 558 515 525 599 507 549 561 567 504 557 596 592 503 549 549 536 590 572 589 540 544 524 553 545 555 543 523 571 577 506 594 519 527 521 587 539 561 569 573 552 587 571 515 585 525 589 512 572 565 516 527 573 579 564 514 557 518 595 509 518 549 549 541 580 535 531 540 596 516 ...
output:
0 TAKE 1 1 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 1 2 TAKE 0 IGNORE 0 IGNORE 1 6 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 1 9 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 1 13 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IG...
result:
ok OK, worst = 0.836394 (100 test cases)
Test #7:
score: 0
Accepted
time: 4ms
memory: 3600kb
input:
10 1000 535 529 536 588 558 515 525 599 507 549 561 567 504 557 596 592 503 549 549 536 590 572 589 540 544 524 553 545 555 543 523 571 577 506 594 519 527 521 587 539 561 569 573 552 587 571 515 585 525 589 512 572 565 516 527 573 579 564 514 557 518 595 509 518 549 549 541 580 535 531 540 596 516 ...
output:
0 TAKE 1 1 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 1 2 TAKE 0 IGNORE 0 IGNORE 1 6 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 1 9 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 1 13 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IG...
result:
ok OK, worst = 0.836394 (10 test cases)
Test #8:
score: 0
Accepted
time: 43ms
memory: 3960kb
input:
1 10000 535 529 536 588 558 515 525 599 507 549 561 567 504 557 596 592 503 549 549 536 590 572 589 540 544 524 553 545 555 543 523 571 577 506 594 519 527 521 587 539 561 569 573 552 587 571 515 585 525 589 512 572 565 516 527 573 579 564 514 557 518 595 509 518 549 549 541 580 535 531 540 596 516 ...
output:
0 TAKE 1 1 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 1 2 TAKE 0 IGNORE 0 IGNORE 1 6 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 1 9 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 1 13 TAKE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IGNORE 0 IG...
result:
ok OK, worst = 0.836394 (1 test case)
Test #9:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
1 2 2 999
output:
0 TAKE 1 1 TAKE
result:
ok OK, worst = 1.000000 (1 test case)
Test #10:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
100 3 551 450 550 3 552 449 551 3 553 448 552 3 554 447 553 3 555 446 554 3 556 445 555 3 557 444 556 3 558 443 557 3 559 442 558 3 560 441 559 3 561 440 560 3 562 439 561 3 563 438 562 3 564 437 563 3 565 436 564 3 566 435 565 3 567 434 566 3 568 433 567 3 569 432 568 3 570 431 569 3 571 430 570 3 ...
output:
0 TAKE 1 1 TAKE 0 TAKE 0 TAKE 1 1 TAKE 0 TAKE 0 TAKE 1 1 TAKE 0 TAKE 0 TAKE 1 1 TAKE 0 TAKE 0 TAKE 1 1 TAKE 0 TAKE 0 TAKE 1 1 TAKE 0 TAKE 0 TAKE 1 1 TAKE 0 TAKE 0 TAKE 1 1 TAKE 0 TAKE 0 TAKE 1 1 TAKE 0 TAKE 0 TAKE 1 1 TAKE 0 TAKE 0 TAKE 1 1 TAKE 0 TAKE 0 TAKE 1 1 TAKE 0 TAKE 0 TAKE 1 1 TAKE 0 TAKE 0...
result:
ok OK, worst = 0.600000 (100 test cases)
Test #11:
score: -100
Wrong Answer
time: 9ms
memory: 3612kb
input:
41 238 1 0 0 4 1 2 0 5 0 5 1 5 2 3 5 1 1 5 5 2 1 3 4 1 5 0 4 1 5 3 1 4 4 1 1 4 2 2 1 0 4 1 5 1 2 4 3 4 0 2 2 0 3 3 4 2 2 1 2 0 3 5 3 3 1 2 4 3 3 3 0 3 1 1 0 4 5 4 1 3 5 2 0 1 0 2 3 0 5 4 5 5 5 1 5 5 5 2 1 4 0 0 4 3 2 5 0 4 1 1 5 3 5 2 3 1 3 3 0 2 3 1 2 3 5 0 5 2 3 5 3 0 3 4 1 0 1 3 1 2 0 4 5 4 3 0 4...
output:
0 TAKE 0 IGNORE 0 IGNORE 0 TAKE 0 TAKE 0 TAKE 0 IGNORE 0 TAKE 0 IGNORE 0 TAKE 0 TAKE 0 TAKE 0 TAKE 0 TAKE 0 TAKE 0 TAKE 0 TAKE 0 TAKE 0 TAKE 0 TAKE 0 TAKE 0 TAKE 0 TAKE 0 TAKE 0 TAKE 0 IGNORE 0 TAKE 0 TAKE 0 TAKE 0 TAKE 0 TAKE 0 TAKE 0 TAKE 0 TAKE 0 TAKE 0 TAKE 0 TAKE 0 TAKE 0 TAKE 0 IGNORE 0 TAKE 0...
result:
wrong answer alg = 411 opt = 1000 (test case 2)