25012023-01-14 10:28:39peterVideójátékcpp17Wrong answer 0/10056ms7340 KiB
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>

int off() {
	int T, myBreaks, HanoBreaks;
	scanf("%d", &T);
	scanf("%d", &myBreaks);
	int** AB = (int**)malloc(sizeof(int*) * myBreaks);
	for (int i = 0; i < myBreaks; i++)
	{
		AB[i] = (int*)malloc(sizeof(int) * 2);
		scanf("%d%d", &AB[i][0], &AB[i][1]);
	}
	scanf("%d", &HanoBreaks);
	int** XY = (int**)malloc(sizeof(int*) * HanoBreaks);
	for (int i = 0; i < HanoBreaks; i++)
	{
		XY[i] = (int*)malloc(sizeof(int) * 2);
		scanf("%d%d", &XY[i][0], &XY[i][1]);
	}

	
	int* start = (int*)malloc(sizeof(int) * (myBreaks + HanoBreaks));
	int* end = (int*)malloc(sizeof(int) * (myBreaks + HanoBreaks));
	int a = 0, b = 0, c = 0;
	for (int i = 0; i < myBreaks + HanoBreaks; i++)
	{
		if (a >= myBreaks)
		{
			start[c] = XY[b][0];
			c++;
			b++;
			continue;
		}
		if (b >= HanoBreaks)
		{
			start[c] = AB[a][0];
			c++;
			a++;
			continue;
		}
		if (AB[a][0] <= XY[b][0])
		{
			start[c] = AB[a][0];
			c++;
			a++;
			continue;
		}
		start[c] = XY[b][0];
		c++;
		b++;
	}
	a = 0; b = 0; c = 0;
	for (int i = 0; i < myBreaks + HanoBreaks; i++)
	{
		if (a >= myBreaks)
		{
			end[c] = XY[b][1];
			c++;
			b++;
			continue;
		}
		if (b >= HanoBreaks)
		{
			end[c] = AB[a][1];
			c++;
			a++;
			continue;
		}
		if (AB[a][1] <= XY[b][1])
		{
			end[c] = AB[a][1];
			c++;
			a++;
			continue;
		}
		end[c] = XY[b][1];
		c++;
		b++;
	}


	int s = 0, e = 0;
	int kozos = 0;
	for (int i = 0; i < (myBreaks + HanoBreaks) * 2; i++)
	{
		if (start[s] <= end[e])
		{
			s++;
		}
		else
		{
			e++;
			int interval = end[e - 1] - start[s - 1] + 1;
			if (interval > 0)
			{
				kozos += interval;
			}
		}
		
	}

	printf("%d", kozos);





	for (int i = 0; i < myBreaks; i++)
	{
		free(AB[i]);
	}
	for (int i = 0; i < HanoBreaks; i++)
	{
		free(XY[i]);
	}
	free(AB);
	free(XY);
	free(start);
	free(end);
	return 0;
}

int main() {
	int T, myBreaks, HanoBreaks;
	scanf("%d", &T);
	scanf("%d", &myBreaks);
	int* AB = (int*)malloc(sizeof(int) * myBreaks * 2);
	for (int i = 0; i < myBreaks * 2; i += 2)
	{
		scanf("%d%d", &AB[i], &AB[i + 1]);
	}
	scanf("%d", &HanoBreaks);
	int* XY = (int*)malloc(sizeof(int) * HanoBreaks * 2);
	for (int i = 0; i < HanoBreaks * 2; i += 2)
	{
		scanf("%d%d", &XY[i], &XY[i + 1]);
	}


	int a = 0, b = 0, kozos = 0;
	while (a < myBreaks * 2 && b < HanoBreaks * 2)
	{
		if (XY[b] - AB[a] > T)
		{
			a += 2;
			continue;
		}
		if (AB[a] <= XY[b] && AB[a + 1] >= XY[b])
		{
			if (XY[b + 1] < AB[a + 1])
			{
				kozos += XY[b + 1] - XY[b] + 1;
				b += 2;
				continue;
			}
			kozos += AB[a + 1] - XY[b] + 1;
		}
		if (AB[a] <= XY[b + 1])
		{
			if (AB[a + 1] < XY[b + 1])
			{
				kozos += AB[a + 1] - AB[a] + 1;
				a += 2;
				continue;
			}
			kozos += XY[b + 1] - AB[a] + 1;
		}
		a += 2;
	}

	printf("%d", kozos);
	free(AB);
	free(XY);
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1424 KiB
2Accepted2ms1572 KiB
subtask20/10
3Accepted2ms1712 KiB
4Accepted2ms1912 KiB
5Wrong answer2ms2116 KiB
6Accepted2ms2308 KiB
7Accepted2ms2572 KiB
8Accepted2ms2704 KiB
9Accepted2ms2812 KiB
10Accepted2ms2720 KiB
11Wrong answer2ms2752 KiB
subtask30/20
12Wrong answer2ms2904 KiB
13Wrong answer2ms2988 KiB
14Wrong answer2ms3220 KiB
15Wrong answer2ms3392 KiB
16Wrong answer2ms3360 KiB
17Wrong answer2ms3452 KiB
18Wrong answer2ms3576 KiB
19Wrong answer2ms3396 KiB
20Wrong answer2ms3324 KiB
21Wrong answer2ms3340 KiB
22Wrong answer2ms3364 KiB
subtask40/30
23Wrong answer6ms3580 KiB
24Wrong answer17ms4172 KiB
25Wrong answer43ms5728 KiB
26Wrong answer46ms6400 KiB
27Wrong answer46ms6256 KiB
28Wrong answer18ms4428 KiB
29Wrong answer4ms3868 KiB
30Wrong answer4ms4216 KiB
31Wrong answer3ms4020 KiB
subtask50/40
32Wrong answer7ms4220 KiB
33Wrong answer19ms4820 KiB
34Wrong answer37ms5960 KiB
35Wrong answer50ms6580 KiB
36Wrong answer56ms7108 KiB
37Wrong answer56ms7340 KiB
38Wrong answer32ms6132 KiB
39Wrong answer37ms6684 KiB
40Wrong answer10ms4648 KiB
41Wrong answer16ms5052 KiB