Submission details
Task:Ryhmät
Sender:Metabolix
Submission time:2025-09-27 08:19:27 +0300
Language:C++ (C++17)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.01 s1, 2, 3details
#20.01 s1, 2, 3details
#3ACCEPTED0.01 s1, 2, 3details
#4ACCEPTED0.01 s1, 2, 3details
#5ACCEPTED0.01 s1, 2, 3details
#6ACCEPTED0.16 s2details
#7ACCEPTED0.17 s2details
#8ACCEPTED0.23 s2details
#9ACCEPTED0.14 s2, 3details
#10--3details
#11--3details
#12--3details
#13--3details
#14--3details
#15--3details
#16--3details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:54:37: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |         if (toiveet_alkaneet.size() >= koko) {
      |             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~

Code

#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
 
using namespace std;

typedef pair<int, int> P;

int main() {
    iostream::sync_with_stdio(false);
    int n, t;
    cin >> n >> t;
    vector<pair<int, int>> toiveet(n);
    for (int i = 0; i < n; i++) {
        cin >> toiveet[i].first >> toiveet[i].second;
    }
    sort(toiveet.begin(), toiveet.end());

    vector<vector<int>> testit(t);
    set<int> ryhmäkoot;
    for (auto &testi : testit) {
        int ryhmien_maara;
        cin >> ryhmien_maara;
        testi.resize(ryhmien_maara);
        for (int i = 0; i < ryhmien_maara; i++) {
            cin >> testi[i];
            ryhmäkoot.insert(testi[i]);
        }
        sort(testi.begin(), testi.end());
    }

    unordered_map<int, vector<int>> toiveet_ryhmässä(n + 1);
    auto vertaa_indeksilla = [&](int i, int j) {
        return toiveet[i].second < toiveet[j].second;
    };
    vector<int> toiveet_alkaneet;
    int toive_i = 0;
    for (int koko: ryhmäkoot) {
        while (!toiveet_alkaneet.empty() && toiveet[toiveet_alkaneet[0]].second < koko) {
            pop_heap(toiveet_alkaneet.begin(), toiveet_alkaneet.end(), vertaa_indeksilla);
            toiveet_alkaneet.pop_back();
        }
        while (toive_i < n && toiveet[toive_i].first <= koko) {
            if (toiveet[toive_i].second >= koko) {
                toiveet_alkaneet.push_back(toive_i);
                push_heap(toiveet_alkaneet.begin(), toiveet_alkaneet.end(), vertaa_indeksilla);
            }
            toive_i++;
        }
        if (toiveet_alkaneet.size() >= koko) {
            toiveet_ryhmässä[koko] = toiveet_alkaneet;
            sort_heap(toiveet_ryhmässä[koko].begin(), toiveet_ryhmässä[koko].end(), vertaa_indeksilla);
        }
    }

    for (int _ = 0; _ < t; _++) {
        if (0) {
            ei:;
            cout << "NO\n";
            continue;
        }
        vector<int> ryhmät = testit[_];
        unordered_set<int> käytetyt;
        int prev_koko = 0;
        auto toiveet_iter = toiveet_ryhmässä[0].begin();
        for (int koko : ryhmät) {
            if (prev_koko != koko) {
                prev_koko = koko;
                toiveet_iter = toiveet_ryhmässä[koko].begin();
            }
            for (int lapsi = 0; lapsi < koko; lapsi++) {
                while (toiveet_iter != toiveet_ryhmässä[koko].end() && käytetyt.count(*toiveet_iter)) {
                    toiveet_iter++;
                }
                if (toiveet_iter == toiveet_ryhmässä[koko].end()) {
                    goto ei;
                }
                käytetyt.insert(*toiveet_iter);
                toiveet_iter++;
            }
        }
        cout << "YES\n";
    }
}

Test details

Test 1

Group: 1, 2, 3

Verdict:

input
100 100
10 10
10 10
6 9
6 8
...

correct output
YES
YES
YES
NO
YES
...

user output
YES
YES
YES
NO
YES
...

Test 2

Group: 1, 2, 3

Verdict:

input
100 100
9 9
6 10
8 10
8 8
...

correct output
NO
YES
NO
YES
NO
...

user output
NO
YES
NO
YES
NO
...

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

input
100 100
1 1
1 1
1 1
1 1
...

correct output
YES
YES
YES
YES
YES
...

user output
YES
YES
YES
YES
YES
...

Test 4

Group: 1, 2, 3

Verdict: ACCEPTED

input
100 100
100 100
100 100
100 100
100 100
...

correct output
YES
YES
YES
YES
YES
...

user output
YES
YES
YES
YES
YES
...

Test 5

Group: 1, 2, 3

Verdict: ACCEPTED

input
100 100
4 9
3 8
7 9
7 9
...

correct output
NO
NO
NO
NO
NO
...

user output
NO
NO
NO
NO
NO
...

Test 6

Group: 2

Verdict: ACCEPTED

input
1000 1000
9 10
2 5
10 10
5 5
...

correct output
YES
YES
YES
YES
NO
...

user output
YES
YES
YES
YES
NO
...

Test 7

Group: 2

Verdict: ACCEPTED

input
1000 1000
5 7
9 9
3 7
8 10
...

correct output
YES
NO
NO
YES
YES
...

user output
YES
NO
NO
YES
YES
...

Test 8

Group: 2

Verdict: ACCEPTED

input
1000 1000
1 1
1 1
1 1
1 1
...

correct output
YES
YES
YES
YES
YES
...

user output
YES
YES
YES
YES
YES
...

Test 9

Group: 2, 3

Verdict: ACCEPTED

input
1000 1000
1000 1000
1000 1000
1000 1000
1000 1000
...

correct output
YES
YES
YES
YES
YES
...

user output
YES
YES
YES
YES
YES
...

Test 10

Group: 3

Verdict:

input
100000 1000
774 778
363 852
309 668
261 459
...

correct output
YES
YES
YES
YES
YES
...

user output
(empty)

Test 11

Group: 3

Verdict:

input
100000 1000
1233 1914
901 3963
1277 4293
1083 1599
...

correct output
NO
NO
YES
NO
NO
...

user output
(empty)

Test 12

Group: 3

Verdict:

input
100000 1000
1970 8631
4606 5797
6317 8162
8204 8789
...

correct output
NO
NO
NO
NO
NO
...

user output
(empty)

Test 13

Group: 3

Verdict:

input
100000 1000
1000 1000
1000 1000
1000 1000
1000 1000
...

correct output
YES
YES
YES
YES
YES
...

user output
(empty)

Test 14

Group: 3

Verdict:

input
100000 100000
1 100000
1 100000
1 100000
1 100000
...

correct output
YES
YES
YES
YES
YES
...

user output
(empty)

Test 15

Group: 3

Verdict:

input
100000 100000
80971 98445
93046 96043
74840 94035
95931 96609
...

correct output
NO
NO
NO
NO
NO
...

user output
(empty)

Test 16

Group: 3

Verdict:

input
100000 10000
6481 14350
69129 87600
6217 16462
4387 16625
...

correct output
YES
YES
YES
YES
YES
...

user output
(empty)