QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#546858#9178. All-You-Can-EatFork512HzWA 34ms3804kbC++202.9kb2024-09-04 14:50:042024-09-04 14:50:04

Judging History

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

  • [2024-09-04 14:50:04]
  • 评测
  • 测评结果:WA
  • 用时:34ms
  • 内存:3804kb
  • [2024-09-04 14:50:04]
  • 提交

answer

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<utility>
#include<vector>
#include<functional>
#include<deque>
#include<set>
#include<cmath>
using namespace std;
typedef pair<long long, long long> pii;
typedef vector<long long> vll;
typedef long long ll;
typedef long long i64;

//#define DEBUG

#ifdef DEBUG
const long long N = 1000;
#endif
#ifndef DEBUG
const long long N = 10100;
#endif
// const ll M = 998244353;
inline ll read()
{
	ll tmp;
	if(!(cin >> tmp))
		exit(0);
	return tmp;
}
inline void clr()
{
	fflush(stdout);
}
ll n, a[N];
set<pii> table;
int main()
{
    #ifdef DEBUG
    freopen("1.txt", "r", stdin);
    #endif
//    #ifndef DEBUG
//    ios::sync_with_stdio(false);
//    cin.tie(nullptr);
//    cout.tie(nullptr);
//    #endif
    int z;
    //z = 1;
    cin >> z;
    while(z--){
		n = read();
		table.clear();
		ll s = 0;
		bool win = 0;
		for(ll i=1; i<=n; i++)
		{
			cerr << s << '\n';
			a[i] = read();
			if(win || a[i] == 0)
			{
				cerr << "Win0\n";
				cout << "0\nIGNORE\n";
				clr();
				continue;
			}
			
			if(a[i] >= 600)
			{
				win = 1;
				cout << table.size() << ' ';
				for(pii j: table) cout << j.second << ' ';
				cout << '\n';
				cerr << "Singular600\n";
				cout << "TAKE\n";
				clr();
				continue;
			}
			
			if(s + a[i] <= 1000)
			{
				s += a[i];
				table.insert({a[i], i});
				cerr << "GreedyTake\n";
				cout << "0\nTAKE\n";
				if(s >= 600) win = 1;
				clr();
				continue;
			}
			
			// Now: a[i] \in [402,599], s < 600
			
			auto mx = table.end(); mx--;
			if(mx->first + a[i] >= 600 && mx->first + a[i] <= 1000)
			{
				win = 1;
				cout << table.size() - 1 << ' ';
				for(auto i = table.begin(); i != mx; i++)
					cout << i->second << ' ';
				
				cout << "\nTAKE\n";
				cerr << "Pair600_max1\n";
				clr();
				continue;
			}
			if(mx != table.begin())
			{
				mx--;
				if(mx->first + a[i] >= 600 && mx->first + a[i] <= 1000)
				{
					win = 1;
					cout << table.size() - 1 << ' ';
					for(auto i = table.begin(); i != mx; i++)
						cout << i->second << ' ';
					mx++;
					cout << mx->second << '\n';
					cerr << "Pair600_max2\n";
					cout << "TAKE\n";
					clr();
					continue;
				}
				mx++;
			}
			// Now: a[i] \in [402,599], s < 600,
			// max + a[i] > 1k, second largest + a[i] < 600, 
			// max >= 402, second largest <= 197
			if(mx->first > a[i])
			{
				cerr << "MaxReplace\n";
				cout << "1 " << mx->second << "\nTAKE\n";
				s -= mx->first;
				s += a[i];
				table.erase(mx);
				table.insert({a[i], i});
			}
			else cout << "0\nIGNORE\n";
			clr();
		}
    }
 	return 0;
}
/*BEFORE SUBMISSION:
1. remove #define DEBUG
2. check data constraints
3. check memory reset for multitest
4. check integer overflow
5. parenthesize all bitwise operations
6. run all sample tests in random order
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3640kb

input:

1
5
10
13
450
585
465

output:

0
TAKE
0
TAKE
0
TAKE
0
IGNORE
0
TAKE

result:

ok OK, worst = 1.000000 (1 test case)

Test #2:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

1
1
100

output:

0
TAKE

result:

ok OK, worst = 1.000000 (1 test case)

Test #3:

score: 0
Accepted
time: 16ms
memory: 3592kb

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: 19ms
memory: 3660kb

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

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

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: 34ms
memory: 3588kb

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: 13ms
memory: 3804kb

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

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: 2ms
memory: 3644kb

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: 17ms
memory: 3712kb

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 = 599 opt = 1000 (test case 2)