Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
12 kB
7
Indexable
------------------MAIN-------------------
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <stdio.h>
#include <string.h>

struct Result
{
	int mPrice;
	int mPerformance;
};

extern void init(int mCharge);
extern Result order(int mBudget);
extern int stock(int mType, int mPerformance, int mPrice, int mPosition);

/////////////////////////////////////////////////////////////////////////

#define INIT	0
#define STOCK	1
#define ORDER	2

static bool run()
{
	int cmd, ans, ans2, ret;
	int in, in2, in3, in4;
	int Q = 0;
	bool okay = false;
	Result Ret;

	scanf("%d", &Q);

	for (int q = 0; q < Q; ++q)
	{
		scanf("%d", &cmd);

		switch (cmd)
		{
		case INIT:
			scanf("%d", &in);
			init(in);
			okay = true;
			break;

		case STOCK:
			scanf("%d %d %d %d", &in, &in2, &in3, &in4);
			ret = stock(in, in2, in3, in4);
			scanf("%d", &ans);
			if (ret != ans)
				okay = false;
			break;

		case ORDER:
			scanf("%d", &in);
			Ret = order(in);
			scanf("%d %d", &ans, &ans2);
			if (Ret.mPrice != ans || Ret.mPerformance != ans2)
				okay = false;
			break;

		default:
			okay = false;
		}
	}

	return okay;
}
int main()
{
	setbuf(stdout, NULL);
	freopen("sample_input.txt", "r", stdin);

	int T, MARK;
	scanf("%d %d", &T, &MARK);

	for (int tc = 1; tc <= T; tc++)
	{
		int score = run() ? MARK : 0;
		printf("#%d %d\n", tc, score);
	}

	return 0;
}

-----------------------USER---------------------------
#define MAX_COMPONENT 4000
#define MAX_TYPE 3
#define MAX_WAREHOUSE 2
#define min(a, b) (a < b)? a : b

struct Result
{
	int mPrice;
	int mPerformance;
};

Result component[MAX_WAREHOUSE][MAX_TYPE][MAX_COMPONENT];
int cntComponent[MAX_WAREHOUSE][MAX_TYPE];
int choose[MAX_WAREHOUSE+1][MAX_TYPE];
int charge, maxPerformance;

void init(int mCharge)
{
	for(int i = 0; i < MAX_WAREHOUSE; i++){
		for(int j = 0; j < MAX_TYPE; j++){
			cntComponent[i][j] = 0;
		}
	}
	maxPerformance = 0;
	charge = mCharge;
}

int stock(int mType, int mPrice, int mPerformance, int mPosition)
{
	int& cnt = cntComponent[mPosition][mType];
	component[mPosition][mType][cnt].mPerformance = mPerformance;
	component[mPosition][mType][cnt].mPrice = mPrice;
	if(mPerformance > maxPerformance) maxPerformance = mPerformance;
	return ++cnt;
}

Result order(int mBudget)
{
	Result res = { 0, 0 };
	int low = 1;
	int high = maxPerformance;
	int performance;
	int minPrice;

	while(low <= high){
		performance = (low + high)/2;

		//chon nhung linh kien co gia thap nhat o moi kho ma hieu nang lon hon hoac bang performance 
		for(int i = 0; i < MAX_WAREHOUSE; i++){
			for(int j = 0; j < MAX_TYPE; j++){
				minPrice = 1000001;
				for(int k = 0; k < cntComponent[i][j]; k++){
					if(component[i][j][k].mPerformance >= performance && component[i][j][k].mPrice < minPrice){
						minPrice = component[i][j][k].mPrice;
					}
				}
				choose[i][j] = minPrice;
			}
		}

		//chon nhung linh kien co gia thap nhat o ca hai kho ma hieu nang lon hon hoac bang performance 
		for(int j = 0; j < MAX_TYPE; j++){
			choose[2][j] = min(choose[0][j], choose[1][j]);
		}

		//chon truong hop mua tat ca linh kien voi gia thap nhat va hieu nang lon hon hoac bang performance 
		minPrice = min((min(choose[0][0]+choose[0][1]+choose[0][2], choose[1][0]+choose[1][1]+choose[1][2])), choose[2][0]+choose[2][1]+choose[2][2]+charge);


		//kiem tra
		if(minPrice <= mBudget){
			low = performance + 1;
			res.mPerformance = performance;
			res.mPrice = minPrice;
		}
		else
			high = performance - 1;
	}
	return res;
}


------------------------INPUT---------------------------
25 100
16
0 50
1 0 100 200 0 1
1 0 100 200 0 2
1 1 220 120 0 1
1 1 330 160 0 2
1 2 77 50 0 1
1 2 88 150 0 2
1 0 150 150 1 1
1 0 250 300 1 2
1 1 120 100 1 1
1 1 450 200 1 2
1 2 300 200 1 1
1 2 130 70 1 2
2 400 358 100
2 450 408 120
2 346 0 0
36
0 53
1 2 70 736 0 1
1 1 83 885 0 1
1 2 67 675 1 1
1 2 92 973 0 2
1 2 18 188 0 3
1 1 25 277 0 2
1 1 55 594 0 3
1 2 39 419 1 2
1 2 53 579 1 3
1 2 87 968 1 4
1 0 50 548 0 1
1 0 34 348 0 2
1 0 54 587 0 3
1 2 28 301 0 4
2 192 179 587
1 2 45 479 0 5
1 0 71 735 1 1
2 140 134 348
1 1 56 609 1 1
2 200 194 609
1 1 59 612 1 2
1 0 80 808 0 4
1 1 31 320 0 4
1 0 90 948 0 5
1 0 87 929 0 6
1 2 71 765 0 6
2 34 0 0
1 0 92 944 1 2
1 2 14 142 1 5
1 0 41 424 0 7
2 38 0 0
1 1 12 137 1 3
1 1 21 216 0 5
1 2 36 399 1 6
1 1 79 811 1 4
53
0 58
1 0 69 728 1 1
1 0 92 964 1 2
1 0 95 975 1 3
1 1 84 849 1 1
1 1 68 750 0 1
1 0 81 854 1 4
1 0 88 948 0 1
2 142 0 0
1 1 46 487 1 2
1 1 28 300 1 3
1 0 24 260 0 2
1 0 60 641 0 3
1 1 84 889 1 4
1 1 13 141 1 5
1 2 44 452 0 1
1 0 16 181 1 5
1 0 43 465 0 4
1 2 66 728 1 1
1 2 79 865 1 2
1 0 15 159 0 5
1 0 45 494 0 6
1 0 18 188 0 7
1 0 87 954 0 8
1 0 43 462 0 9
1 0 42 425 1 6
1 0 87 875 1 7
2 93 0 0
1 2 11 118 0 2
2 100 95 141
1 2 93 960 0 3
2 226 219 728
1 0 16 173 1 8
1 1 59 633 0 2
1 1 69 751 0 3
1 0 24 264 0 10
1 2 46 499 1 3
2 220 219 728
1 2 94 971 0 4
1 2 76 787 0 5
1 1 62 640 1 6
2 244 244 854
1 0 58 636 0 11
1 0 53 549 0 12
1 0 52 576 0 13
1 0 60 658 0 14
2 246 244 854
1 0 21 233 0 15
1 0 78 837 0 16
1 1 82 902 1 7
1 1 55 582 1 8
1 1 88 884 1 9
1 2 13 140 0 6
71
0 57
1 1 50 541 0 1
1 2 61 642 0 1
1 0 10 116 1 1
1 2 25 277 0 2
1 2 62 648 0 3
1 1 66 680 1 1
1 1 58 608 0 2
1 0 61 671 1 2
1 1 68 734 0 3
1 2 83 865 0 4
1 2 46 493 0 5
1 2 76 848 1 1
1 1 45 467 0 4
1 2 47 514 1 2
1 2 49 514 0 6
1 2 64 660 0 7
1 2 26 296 0 8
1 0 57 570 0 1
1 0 31 317 1 3
1 2 28 312 0 9
1 1 57 611 0 5
1 1 71 789 1 2
1 2 64 667 0 10
1 0 78 807 0 2
1 1 58 600 1 3
1 1 30 336 1 4
2 198 196 611
1 2 32 338 0 11
1 0 14 149 1 4
1 0 66 694 0 3
1 0 55 600 1 5
1 0 52 574 1 6
1 1 69 712 0 6
1 1 50 547 1 5
2 73 0 0
1 0 43 454 0 4
1 2 39 422 1 3
1 2 87 891 0 12
1 0 31 344 1 7
1 0 85 902 0 5
1 1 20 210 0 7
1 0 68 726 0 6
1 2 45 496 1 4
1 1 52 552 1 6
1 1 73 792 1 7
2 290 284 792
1 0 62 656 0 7
1 1 36 403 1 8
2 203 203 671
1 0 38 414 1 8
1 0 28 312 1 9
1 2 47 476 1 5
2 233 229 734
1 1 14 162 1 9
2 75 67 149
2 89 88 210
1 0 70 739 1 10
1 1 92 970 1 10
1 1 85 868 0 8
1 2 21 214 1 6
1 2 54 574 0 13
1 0 28 310 1 11
1 0 13 148 0 8
2 287 257 868
1 0 19 196 0 9
1 2 19 211 0 14
2 298 257 868
2 288 257 868
1 0 62 631 1 12
1 0 55 617 1 13
88
0 54
1 2 48 520 1 1
1 1 74 765 0 1
1 0 81 897 1 1
1 1 74 816 1 1
1 0 54 546 1 2
1 0 63 648 0 1
1 2 88 915 1 2
1 2 24 263 1 3
1 2 49 508 1 4
1 2 21 213 0 1
1 1 82 867 1 2
1 2 89 911 1 5
2 263 251 867
2 127 0 0
1 2 68 759 0 2
1 0 44 459 1 3
1 0 19 194 1 4
1 0 85 912 0 2
1 1 32 350 0 2
1 2 49 516 0 3
1 0 70 761 0 3
1 2 81 902 0 4
1 1 40 423 0 3
2 127 116 213
1 1 58 645 1 3
1 2 70 745 0 5
1 1 56 582 0 4
1 1 65 670 0 5
1 0 16 169 0 4
1 2 81 833 1 6
2 264 251 867
1 2 70 742 0 6
1 0 83 890 0 5
1 2 62 673 0 7
1 2 32 345 0 8
1 0 74 757 0 6
1 1 23 238 0 6
1 2 85 894 1 7
1 0 44 464 0 7
1 1 98 988 0 7
1 1 79 814 1 4
1 0 64 700 0 8
1 2 83 912 1 8
1 0 90 929 1 5
1 1 23 255 1 5
1 2 51 549 0 9
1 0 54 589 0 9
1 0 64 706 0 10
1 1 47 489 0 8
1 2 29 298 1 9
1 0 63 676 0 11
1 0 18 195 0 12
1 0 69 756 1 6
1 0 79 854 0 13
1 0 83 914 0 14
1 0 92 947 1 7
1 2 40 414 0 10
1 1 42 429 1 6
2 230 225 761
2 300 262 902
1 0 60 645 1 8
1 2 95 966 1 10
2 76 62 195
1 2 27 289 1 11
1 2 48 488 1 12
1 2 37 380 1 13
1 0 34 373 0 15
1 2 92 985 0 11
1 0 83 867 0 16
1 1 13 149 1 7
1 2 64 648 0 12
1 1 14 149 1 8
2 70 62 195
1 2 61 642 1 14
1 2 18 193 0 13
2 113 106 350
2 88 78 213
1 1 47 515 1 9
1 1 11 118 1 10
1 1 58 625 1 11
1 1 17 185 0 9
2 137 134 429
1 2 38 405 1 15
1 0 44 477 0 17
1 2 91 928 1 16
2 207 206 706
1 1 54 572 1 12
123
0 446
1 2 170 1778 0 1
1 2 160 1679 0 2
1 2 229 2535 1 1
1 0 17 185 1 1
1 0 607 6161 0 1
1 0 785 8443 1 2
1 0 92 958 1 3
1 1 200 2059 1 1
1 1 660 7082 1 2
1 2 506 5542 1 2
1 2 563 5809 1 3
1 2 65 718 0 3
1 1 491 5317 1 3
1 1 339 3659 1 4
1 1 135 1372 0 1
1 1 925 9704 1 5
1 0 879 8829 1 4
1 2 18 189 0 4
2 441 0 0
1 0 865 9082 0 2
1 1 427 4461 0 2
1 1 110 1179 1 6
1 1 582 5998 0 3
1 0 792 8598 1 5
1 1 323 3240 1 7
1 1 435 4691 1 8
1 1 236 2382 1 9
1 2 265 2766 1 4
1 0 943 9799 0 3
1 2 120 1264 0 5
1 0 487 4903 1 6
1 2 912 9533 0 6
2 2443 2101 5998
2 53 0 0
1 0 28 297 0 4
1 2 73 742 0 7
1 0 482 4908 1 7
1 0 547 5978 1 8
1 2 851 8745 1 5
1 0 883 9810 1 9
2 3201 3166 9533
1 0 944 9607 0 5
1 1 632 6937 1 10
1 2 350 3547 0 8
1 0 866 9365 0 6
1 1 331 3673 1 11
2 2958 2655 8745
1 0 103 1064 0 7
2 1887 1742 5809
1 1 401 4172 0 4
1 2 537 5769 1 6
1 0 499 5442 0 8
1 2 632 6403 0 9
1 1 358 3887 1 12
1 0 734 7931 0 9
1 2 344 3463 0 10
1 0 320 3216 0 10
1 0 613 6224 0 11
1 1 420 4252 0 5
1 0 288 3082 1 10
1 1 741 8002 1 13
1 2 18 195 0 11
2 958 876 2766
1 2 649 7069 1 7
1 2 81 837 1 8
1 0 878 9438 1 11
1 2 572 6044 1 9
1 2 778 8041 1 10
1 1 576 6308 0 6
1 2 893 9064 0 12
2 2575 2568 8598
2 1370 1346 3887
1 1 368 4068 0 7
2 2465 2304 8002
1 0 555 6016 0 12
1 2 685 7057 1 11
1 2 516 5690 1 12
1 1 80 852 0 8
1 0 894 9667 1 12
2 887 876 2766
1 1 360 3621 1 14
2 1657 1544 5317
1 2 205 2133 0 13
1 1 940 9587 0 9
1 1 744 8183 0 10
1 0 944 9511 0 13
1 2 97 1056 1 13
1 1 446 4601 1 15
1 1 40 434 0 11
1 2 701 7348 0 14
1 1 367 3807 1 16
1 0 588 6093 1 13
1 0 224 2282 1 14
2 2913 2795 9533
2 3123 2795 9533
1 2 844 8614 1 14
1 0 112 1189 0 14
1 0 941 9669 0 15
1 0 876 9544 1 15
1 2 590 6128 1 15
1 0 533 5854 1 16
1 0 819 8622 0 16
1 2 545 5707 0 15
1 0 107 1097 1 17
1 2 476 4796 1 16
2 2909 2793 9533
1 0 354 3901 0 17
1 1 644 6933 0 12
1 1 563 5874 1 17
2 1321 1267 3901
1 1 52 548 0 13
1 2 907 9847 1 17
1 1 467 4731 0 14
1 0 58 596 0 18
1 1 748 8144 1 18
2 869 840 2535
1 0 387 4164 0 19
1 1 58 648 1 19
1 0 258 2851 0 20
1 1 678 6820 1 20
1 1 915 9570 1 21
1 0 850 9118 0 21
141
0 435
1 2 800 8801 1 1
1 1 968 9875 1 1
1 0 276 2876 1 1
1 2 718 7673 1 2
1 1 621 6301 1 2
1 0 790 8686 0 1
1 0 807 8145 1 2
1 1 562 5650 1 3
1 2 221 2355 0 1
1 2 337 3447 0 2
1 0 438 4408 0 2
1 0 341 3715 1 3
1 0 24 248 0 3
1 0 373 3809 1 4
1 0 763 8065 0 4
1 0 690 7427 0 5
1 2 773 8340 0 3
1 1 596 6624 0 1
1 0 582 6439 0 6
1 0 413 4320 1 5
1 0 912 9413 1 6
1 1 345 3739 1 4
1 0 885 9716 1 7
1 2 234 2580 0 4
1 0 132 1352 1 8
1 2 245 2463 1 3
2 755 722 1352
1 0 759 8018 0 7
1 1 434 4386 0 2
1 1 594 6472 0 3
1 2 481 5134 0 5
1 1 795 8515 0 4
1 0 56 594 0 8
1 2 752 7825 1 4
1 1 18 195 1 5
1 0 345 3707 1 9
1 2 657 7195 1 5
1 0 638 6970 1 10
2 2753 2653 8801
1 1 958 9662 1 6
1 1 95 1033 1 7
1 1 727 7999 1 8
1 0 505 5296 0 9
2 403 395 195
1 0 678 7056 1 11
1 0 528 5838 0 10
1 1 306 3388 0 5
1 2 412 4430 0 6
2 2170 2062 7056
1 1 429 4551 0 6
1 0 91 985 1 12
1 0 220 2325 0 11
1 2 702 7327 0 7
1 1 561 6014 0 7
2 447 431 985
2 1160 1081 3388
1 0 207 2128 1 13
2 646 472 1033
2 2869 2643 8801
1 1 242 2553 1 9
2 533 472 1033
1 2 595 5991 1 6
1 1 368 3712 1 10
1 1 803 8061 0 8
1 1 120 1214 0 9
1 2 965 9895 1 7
1 2 851 8518 0 8
1 1 775 8416 0 10
1 2 483 4974 0 9
1 1 333 3591 0 11
1 2 839 9104 0 10
2 2884 2818 9716
1 2 261 2662 0 11
1 1 438 4624 0 12
1 2 92 1017 1 8
2 349 319 1017
1 2 917 9580 0 12
1 1 728 7513 1 11
1 1 48 486 0 13
1 0 590 6337 1 14
1 2 145 1583 0 13
2 1550 1547 5134
1 1 745 8191 0 14
1 1 874 9645 1 12
1 2 499 5488 0 14
1 0 280 3053 1 15
1 1 652 7236 1 13
1 0 94 1007 0 12
1 2 230 2536 0 15
1 1 838 8800 1 14
2 2468 2424 8515
2 1554 1547 5134
1 0 957 9737 0 13
2 67 0 0
1 0 301 3311 0 14
1 2 688 7006 0 16
2 991 944 3311
1 0 737 8158 0 15
1 2 359 3962 0 17
1 0 523 5641 1 16
1 2 498 5211 1 9
1 0 649 6675 1 17
1 2 239 2542 1 10
1 0 765 7826 1 18
2 1709 1680 5641
1 1 76 768 1 15
1 1 711 7569 0 15
2 207 201 195
1 0 347 3670 1 19
1 0 941 9465 1 20
2 788 757 2542
1 1 884 9148 1 16
1 1 494 5274 0 16
1 2 832 8932 1 11
1 0 502 5339 1 21
1 1 546 5932 0 17
1 2 29 300 1 12
1 2 468 4693 0 18
1 1 586 6209 0 18
1 1 473 4749 0 19
1 2 775 8145 0 19
1 1 33 355 0 20
1 0 274 2797 0 16
1 2 861 9539 1 13
1 1 775 7887 1 17
1 0 821 8602 0 17
1 0 826 8305 0 18
1 1 413 4254 1 18
1 2 506 5211 0 20
1 0 254 2593 1 22
1 2 395 4271 0 21
2 2822 2818 9716
1 2 42 464 1 14
1 0 134 1350 0 19
1 1 14 148 0 21
1 2 475 5056 0 22
1 2 102 1079 1 15
1 2 736 7444 1 16
1 0 850 8613 1 23
1 0 507 5523 1 24