Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
7.1 kB
32
Indexable
Never
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <stdio.h>

extern void init(int N);
extern int access(int fileId, int fileSize);
extern int usage();

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

#define CMD_INIT 1
#define CMD_ACCESS 2
#define CMD_USAGE 3

static bool run() {
	int q;
	scanf("%d", &q);

	int n, fileId, fileSize;
	int cmd, ans, ret = 0;
	bool okay = false;

	for (int i = 0; i < q; ++i) {
		scanf("%d", &cmd);
		switch (cmd) {
			case CMD_INIT:
				scanf("%d", &n);
				init(n);
				okay = true;
				break;
			case CMD_ACCESS:
				scanf("%d %d %d", &fileId, &fileSize, &ans);
				ret = access(fileId, fileSize);
				if (ans != ret)
					okay = false;
				break;
			case CMD_USAGE:
				ret = usage();
				scanf("%d", &ans);
				if (ans != ret)
					okay = false;
				break;
			default:
				okay = false;
				break;
		}
	}
	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;
}






void init(int N) {
	return;
}

int access(int fileId, int fileSize) {
	return 0;
}

int usage() {
	return 0;
}



25 100
13
1 30
2 111 15 0
2 222 7 15
3 22
2 333 5 22
2 111 15 0
2 444 5 15
3 25
2 555 3 27
2 666 9 0
3 17
2 777 5 9
3 22
50
1 30
2 252957430 26 0
2 386572461 10 0
2 3099869 14 10
2 9228345 3 24
2 861309877 16 0
3 19
2 3099869 14 16
2 604800299 14 0
2 318701078 10 14
2 3099869 14 0
2 252957430 26 0
2 773697865 15 0
2 967744222 12 15
2 861309877 16 0
2 967744222 12 16
2 248332970 12 0
2 402371777 20 0
2 404003848 23 0
2 724645688 4 23
2 709501140 7 0
2 183460036 28 0
2 153469247 13 0
2 90041071 2 13
2 546344016 29 0
2 7835738 21 0
2 99067999 14 0
2 3099869 14 14
3 28
2 7835738 21 0
2 231533489 12 0
2 400980497 3 12
2 843035036 11 15
2 746265243 23 0
2 825458807 6 23
2 642924494 18 0
2 117226182 27 0
2 959211426 14 0
2 404003848 23 0
2 955541694 3 23
3 26
2 125293158 2 26
2 452998853 8 0
2 99067999 14 8
2 774636582 4 22
2 843035036 11 0
2 331383967 27 0
2 553495782 15 0
2 280915947 15 15
3 30




[Example]


Think of the following case in [Table 1].


Order

Function

Return

Figure

1

init(30)

 

Fig. 1

2

access(111, 15)

0

Fig. 2

3

access(222, 7)

15

Fig. 3

4

usage()

22

 

5

access(333, 5)

22

Fig. 4

6

access(111, 15)

0

Fig. 5

7

access(444, 5)

15

Fig. 6

8

usage()

25

 

9

access(555, 3)

27

Fig. 7

10

access(666, 9)

0

Fig. 8

11

usage()

17

 

12

access(777, 5)

9

Fig. 9

13

usage()

22

 

       

                                                                    [Table 1]




(Order #1) A cache with the size of 30 is created. The cache is empty in the initial status.


(Order #2) When access() is called, the file 111 with the size of 15 is accessed. This file is stored because it is not in the cache. Since there is one empty space with the size of 30, 111 is stored in the units of 0 through 14, and 0 is returned. [Fig. 2] shows the result after the function is called.






[Fig. 2]


(Order #3) When access() is called, the file 222 with the size of 7 is accessed. This file is stored because it is not in the cache. Since there is one empty space with the size of 15, 222 is stored in the units of 15 through 21, and 15 is returned. [Fig. 3] shows the result after the function is called.






[Fig. 3]


(Order #4) When usage() is called, the total number of the cache storage units is returned, which store the files. Since the cache has 111 with the size of 15 and 222 with the size of 7, 22, the sum of their file sizes, is returned.


(Order #5) When access() is called, the file 333 with the size of 5 is accessed. This file is stored because it is not in the cache. Since there is one empty space with the size of 8, 333 is stored in the units of 22 through 26, and 22 is returned. [Fig. 4] shows the result after the function is called.







[Fig. 4]


(Order #6) When access() is called, the file 111 with the size of 15 is accessed. Since this file is in the cache, only the time information is updated. 111 is now the most recently accessed file and 222 is the least recently accessed one. [Fig. 5] shows the result after the function is called.







[Fig. 5]


(Order #7) When access() is called, the file 444 with the size of 5 is accessed. This file needs to be stored because it is not in the cache. However, since there is not enough space to store 444, 222, the least recently accessed file, is deleted. This creates an empty space with the size of 7, so 444 can be stored in the units of 15 through 19, and 15 is returned. [Fig. 6] shows the result after the function is called.







[Fig. 6]


(Order #8) When usage() is called, the total number of the storage units is returned, which store the files. Since the cache has 111 with the size of 15, 444 with the size of 5, and 333 with the size of 5, 25, the sum of their file sizes, is returned.


(Order #9) When access() is called, the file 555 with the size of 3 is accessed. This file is stored because it is not in the cache. Because the size of the first empty space is 2 while the size of the second empty space is 3, 555 can be stored in the second space. 555 is stored in the units of 27 through 29, and 27 is returned. [Fig. 7] shows the result after the function is called.







[Fig. 7]


(Order #10) When access() is called, the file 666 with the size of 9 is accessed. This file is stored because it is not in the cache. However, since there is not enough space to store 666, 333, the least recently accessed file, is deleted from the cache. To create more space, 111, the least recently accessed file, is deleted again. 666 is stored in the units of 0 through 8 and 0 is returned. [Fig. 8] shows the result after the function is called.







[Fig. 8]


(Order #11) When usage() is called, the total number of the cache storage units is returned, which store the files. Since the cache has 666 with the size of 9, 444 with the size of 5, and 555 with the size of 3, 17, the sum of their file sizes, is returned.  


(Order #12) When access() is called, the file 777 with the size of 5 is accessed. Because it is not in the cache, 777 is stored in the units of 9 through 13 and 9 is returned. [Fig. 9] shows the result after the function is called.







[Fig. 9]


(Order #13) When usage() is called, the total number of the cache storage units is returned, which store the files. Since the cache has 666 with the size of 9, 777 with the size of 5, 444 with the size of 5, and 555 with the size of 3, 22, the sum of their file sizes, is returned.