18892022-12-07 11:03:18peterRendőrségi Üldözés 4cpp17Time limit exceeded 0/1002.598s4256 KiB
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

bool zolde(int ido, int periodus)
{
	return ido % (2 * periodus) < periodus;	
}

bool lampae(int koordinata, int* lampak, int lampakszama)
{
	for (int i = 0; i < lampakszama; i++)
	{
		if (lampak[i] == koordinata)
		{
			return true;
		}
	}
	return false;
}

int main()
{
	int lampakszama, athaladhat, periodusfele, utcahossz;
	scanf("%d %d %d %d", &lampakszama, &athaladhat, &periodusfele, &utcahossz);

	int* koordinatak = (int*)malloc(sizeof(int) * lampakszama);
	for (int i = 0; i < lampakszama; i++)
	{
		scanf("%d", &koordinatak[i]);
	}

	int ido = 0;
	int koordinata = 0;
	int meglampa = lampakszama;

	do
	{
		if (lampae(koordinata, koordinatak, lampakszama))
		{

			if (zolde(ido, periodusfele))
			{
				koordinata++;
			}
			else
			{
				if (athaladhat == 0)
				{
					; // üres --> várakozik a lámpánál
				}
				else if (athaladhat >= meglampa)
				{
					athaladhat--;
					koordinata++;
				}
				else
				{
					
				}
			}
			meglampa--;
		}
		else
		{
			koordinata++;
		}
		ido++;

	} while (koordinata < utcahossz);

	printf("%d", ido);

	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1368 KiB
2Accepted2ms1696 KiB
subtask20/10
3Time limit exceeded2.598s1812 KiB
4Time limit exceeded2.563s2036 KiB
5Time limit exceeded2.552s1796 KiB
6Time limit exceeded2.572s1872 KiB
7Time limit exceeded2.543s2248 KiB
subtask30/15
8Time limit exceeded2.552s2108 KiB
9Time limit exceeded2.568s2752 KiB
10Time limit exceeded2.563s2744 KiB
11Time limit exceeded2.562s2816 KiB
subtask40/15
12Wrong answer2ms2784 KiB
13Wrong answer2ms3000 KiB
14Wrong answer2ms3052 KiB
15Wrong answer2ms3096 KiB
subtask50/25
16Wrong answer2ms3256 KiB
17Wrong answer2ms3448 KiB
18Wrong answer2ms3432 KiB
19Wrong answer2ms3744 KiB
20Wrong answer2ms3656 KiB
subtask60/15
21Time limit exceeded2.566s3588 KiB
22Time limit exceeded2.552s3524 KiB
23Time limit exceeded2.552s3808 KiB
24Time limit exceeded2.579s3784 KiB
25Time limit exceeded2.563s4000 KiB
subtask70/20
26Time limit exceeded2.548s4012 KiB
27Time limit exceeded2.562s4256 KiB
28Time limit exceeded2.562s4248 KiB
29Time limit exceeded2.546s4196 KiB
30Time limit exceeded2.578s3848 KiB