48732023-04-05 13:52:32CWMSzínes szobák (50 pont)cpp17Time limit exceeded 0/50400ms5508 KiB
// Gyak_SzinesSzobak.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int n, c, q;
    cin >> n >> c >> q;
	vector<int> rooms;
	vector<pair<int, int>> Queries;
	for (size_t i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		rooms.push_back(a);
	}
	for (size_t i = 0; i < q; i++)
	{
		int a, b;
		cin >> a >> b;
		Queries.push_back({ a,b });
	}
	int min = 0;
	int max = rooms.size() - 1;
	while (min != max) {
		int mid = (min + max) / 2;
		int place = mid;
		for (size_t i = 0; i < Queries.size(); i++)
		{
			if (rooms[place] == Queries[i].first) {
				place += Queries[i].second;
			}
			if(place<0 || place>rooms.size()-1) {
				if (place < 0) {
					min = mid + 1;
					break;
				}
				else {
					max = mid - 1;
					break;
				}
			}
		}
		if (place > 0) max = mid - 1;
	}
	int boundary1 = min + 1;

	min = 0;
	max = rooms.size() - 1;
	while (min != max) {
		int mid = (min + max) / 2;
		int place = mid;
		for (size_t i = 0; i < Queries.size(); i++)
		{
			if (rooms[place] == Queries[i].first) {
				place += Queries[i].second;
			}
			if (place<0 || place>rooms.size() - 1) {
				if (place < 0) {
					min = mid + 1;
					break;
				}
				else {
					max = mid - 1;
					break;
				}
			}
		}
		if (place > 0) min = mid + 1;
	}
	int boundary2 = min + 1;
	cout << boundary1 - boundary2 + n + 1;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base0/50
1Accepted0/03ms1812 KiB
2Time limit exceeded0/0377ms2920 KiB
3Time limit exceeded0/1347ms2072 KiB
4Wrong answer0/13ms2132 KiB
5Time limit exceeded0/1400ms2176 KiB
6Wrong answer0/13ms2436 KiB
7Time limit exceeded0/1398ms2636 KiB
8Wrong answer0/13ms2896 KiB
9Time limit exceeded0/1400ms2936 KiB
10Wrong answer0/14ms3236 KiB
11Time limit exceeded0/1400ms3416 KiB
12Time limit exceeded0/1363ms3380 KiB
13Time limit exceeded0/1375ms3208 KiB
14Time limit exceeded0/1367ms3964 KiB
15Time limit exceeded0/1323ms3188 KiB
16Time limit exceeded0/1342ms3484 KiB
17Time limit exceeded0/1358ms3700 KiB
18Time limit exceeded0/1367ms3872 KiB
19Time limit exceeded0/1375ms4712 KiB
20Time limit exceeded0/1379ms5224 KiB
21Time limit exceeded0/1367ms4924 KiB
22Time limit exceeded0/1354ms5448 KiB
23Time limit exceeded0/1367ms5508 KiB
24Time limit exceeded0/1363ms5404 KiB
25Time limit exceeded0/1363ms5484 KiB
26Time limit exceeded0/1365ms5296 KiB
27Time limit exceeded0/3367ms5236 KiB
28Time limit exceeded0/3368ms5356 KiB
29Time limit exceeded0/3379ms5284 KiB
30Time limit exceeded0/3352ms5276 KiB
31Time limit exceeded0/3368ms5492 KiB
32Time limit exceeded0/3363ms5392 KiB
33Time limit exceeded0/4368ms4512 KiB
34Time limit exceeded0/4365ms5076 KiB