QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#697733#9178. All-You-Can-Eatucup-team4975RE 32ms3880kbC++232.9kb2024-11-01 15:31:352024-11-01 15:31:35

Judging History

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

  • [2024-11-01 15:31:35]
  • 评测
  • 测评结果:RE
  • 用时:32ms
  • 内存:3880kb
  • [2024-11-01 15:31:35]
  • 提交

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);
				assert(cnt >= 2);
				flag = 1, vis[i] = 1;
				vector<int> las(1010, 0), dp(1010, 0);
				vector<int> ans;
				dp[0] = 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;
					}
				}
				assert(st >= 600);
				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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3544kb

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: 3880kb

input:

1
1
100

output:

0
TAKE

result:

ok OK, worst = 1.000000 (1 test case)

Test #3:

score: 0
Accepted
time: 17ms
memory: 3876kb

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: 16ms
memory: 3640kb

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: 9ms
memory: 3580kb

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: 15ms
memory: 3808kb

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: 14ms
memory: 3592kb

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: 32ms
memory: 3716kb

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: 1ms
memory: 3880kb

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: 3676kb

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
Runtime Error

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: