6096 | 2023-10-29 18:21:40 | Gervid | Zsonglőrködés | cpp17 | Accepted 100/100 | 477ms | 82584 KiB |
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main()
{
int n, i, j = 0, k, out = 0, temp;
cin >> n;
vector<pair<int, int>> intervals(n); //fordított sorrendben experimenting
map<int, vector<int>> startsat;
for (i = 0; i < n; i++)
{
cin >> intervals[i].second >> intervals[i].first;
}
sort(intervals.begin(), intervals.end());
for (i = 0; i < n; i++)
{
if (startsat.count(intervals[i].second) == 0)
{
startsat[intervals[i].second] = { i };
}
else
{
startsat[intervals[i].second].push_back(i);
}
}
for (i = 0; i < n; i++)
{
out++;
while (intervals[j].second == -1)
{
j++;
}
intervals[j].second = -1;
k = intervals[j].first;
while (startsat[k].size() > 0)
{
temp = k;
k = intervals[startsat[temp].back()].first;
intervals[startsat[temp].back()].second = -1;
startsat[temp].pop_back();
i++;
}
}
cout << out;
}
//4
//4 9
//2 4
//9 12
//1 4
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1816 KiB | ||||
2 | Accepted | 3ms | 2048 KiB | ||||
subtask2 | 20/20 | ||||||
3 | Accepted | 6ms | 3072 KiB | ||||
4 | Accepted | 122ms | 25652 KiB | ||||
5 | Accepted | 338ms | 60992 KiB | ||||
6 | Accepted | 416ms | 72888 KiB | ||||
7 | Accepted | 439ms | 81116 KiB | ||||
8 | Accepted | 439ms | 81392 KiB | ||||
9 | Accepted | 470ms | 81112 KiB | ||||
10 | Accepted | 472ms | 81404 KiB | ||||
11 | Accepted | 437ms | 81724 KiB | ||||
subtask3 | 35/35 | ||||||
12 | Accepted | 3ms | 3860 KiB | ||||
13 | Accepted | 3ms | 3836 KiB | ||||
14 | Accepted | 3ms | 3940 KiB | ||||
15 | Accepted | 3ms | 4132 KiB | ||||
16 | Accepted | 3ms | 4176 KiB | ||||
17 | Accepted | 4ms | 4208 KiB | ||||
18 | Accepted | 3ms | 4428 KiB | ||||
19 | Accepted | 4ms | 4512 KiB | ||||
20 | Accepted | 4ms | 4356 KiB | ||||
subtask4 | 45/45 | ||||||
21 | Accepted | 6ms | 5032 KiB | ||||
22 | Accepted | 64ms | 5856 KiB | ||||
23 | Accepted | 344ms | 62824 KiB | ||||
24 | Accepted | 188ms | 8972 KiB | ||||
25 | Accepted | 477ms | 82376 KiB | ||||
26 | Accepted | 210ms | 9376 KiB | ||||
27 | Accepted | 441ms | 82516 KiB | ||||
28 | Accepted | 209ms | 9588 KiB | ||||
29 | Accepted | 441ms | 82584 KiB |