| Task: | Ryhmät |
| Sender: | Metabolix |
| Submission time: | 2025-09-28 11:01:33 +0300 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | 10 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 10 |
| #2 | TIME LIMIT EXCEEDED | 0 |
| #3 | TIME LIMIT EXCEEDED | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
| #2 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
| #3 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
| #4 | ACCEPTED | 0.00 s | 1, 2, 3 | details |
| #5 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
| #6 | TIME LIMIT EXCEEDED | -- | 2 | details |
| #7 | TIME LIMIT EXCEEDED | -- | 2 | details |
| #8 | ACCEPTED | 0.17 s | 2 | details |
| #9 | ACCEPTED | 0.01 s | 2, 3 | details |
| #10 | TIME LIMIT EXCEEDED | -- | 3 | details |
| #11 | TIME LIMIT EXCEEDED | -- | 3 | details |
| #12 | TIME LIMIT EXCEEDED | -- | 3 | details |
| #13 | ACCEPTED | 0.59 s | 3 | details |
| #14 | ACCEPTED | 0.10 s | 3 | details |
| #15 | ACCEPTED | 0.62 s | 3 | details |
| #16 | ACCEPTED | 0.10 s | 3 | details |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:89:37: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
89 | if (toiveet_voimassa.size() < koko) {
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~Code
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <map>
using namespace std;
typedef pair<int, int> P;
struct Vaihe {
int edellinen_vaihe;
int ryhmän_koko;
bool onnistuu = false;
unordered_set<int> käytetyt;
unordered_map<int, int> jatkot;
};
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);
int ryhmien_määrä_yhteensä = 0;
for (auto &testi : testit) {
int ryhmien_määrä;
cin >> ryhmien_määrä;
testi.resize(ryhmien_määrä);
for (int i = 0; i < ryhmien_määrä; i++) {
cin >> testi[i];
}
sort(testi.begin(), testi.end());
ryhmien_määrä_yhteensä += ryhmien_määrä;
}
// Tehdään graafi
vector<int> vastausvaiheet;
vector<Vaihe> vaiheet;
vaiheet.reserve(ryhmien_määrä_yhteensä + 1);
vaiheet.push_back(Vaihe{-1, 0, true});
for (auto& testi : testit) {
int vaihe = 0;
for (int koko : testi) {
if (!vaiheet[vaihe].jatkot.count(koko)) {
vaiheet[vaihe].jatkot[koko] = (int)vaiheet.size();
vaiheet.push_back(Vaihe{vaihe, koko});
}
vaihe = vaiheet[vaihe].jatkot[koko];
}
vastausvaiheet.push_back(vaihe);
}
set<P> seuraavat;
for (auto& jatko : vaiheet[0].jatkot) {
seuraavat.insert({jatko.first, jatko.second});
}
set<P> toiveet_voimassa;
int toive_i = 0;
const int d = 0;
while (!seuraavat.empty()) {
int koko, vaihe_i;
tie(koko, vaihe_i) = *seuraavat.begin();
seuraavat.erase(seuraavat.begin());
if(d) cout << "Koko " << koko << ", vaihe " << vaihe_i << "\n";
while (!toiveet_voimassa.empty() && toiveet_voimassa.begin()->first < koko) {
if (d) cout << " - " << toiveet[toiveet_voimassa.begin()->second].first << " " << toiveet[toiveet_voimassa.begin()->second].second << "\n";
toiveet_voimassa.erase(toiveet_voimassa.begin());
}
while (toive_i < n && toiveet[toive_i].first <= koko) {
if (toiveet[toive_i].second >= koko) {
if (d) cout << " + " << toiveet[toive_i].first << " " << toiveet[toive_i].second << "\n";
toiveet_voimassa.insert({toiveet[toive_i].second, toive_i});
}
toive_i++;
}
if (toiveet_voimassa.size() < koko) {
if(d) cout << " -> ei onnistu, jatketaan\n";
continue; // Tämä vaihe ei onnistu, jatkoja ei ole syytä tutkia.
}
auto& vaihe = vaiheet[vaihe_i];
int puuttuu = koko;
for (auto toive: toiveet_voimassa) {
int toive_i = toive.second;
if (vaihe.käytetyt.count(toive_i)) continue;
vaihe.käytetyt.insert(toive_i);
puuttuu--;
if (puuttuu == 0) break;
}
if (puuttuu == 0) {
vaihe.onnistuu = true;
for (auto& jatko : vaihe.jatkot) {
if(d) cout << " == " << jatko.first << " " << jatko.second << "\n";
seuraavat.insert({jatko.first, jatko.second});
vaiheet[jatko.second].käytetyt = vaihe.käytetyt;
}
vaihe.käytetyt.clear();
vaihe.jatkot.clear();
} else {
if(d) cout << " -> ei onnistu, jatketaan\n";
}
}
for (auto i: vastausvaiheet) {
cout << (vaiheet[i].onnistuu ? "YES\n" : "NO\n");
}
}
Test details
Test 1
Group: 1, 2, 3
Verdict: ACCEPTED
| 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 ... Truncated |
Test 2
Group: 1, 2, 3
Verdict: ACCEPTED
| 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 ... Truncated |
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 ... Truncated |
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 ... Truncated |
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 ... Truncated |
Test 6
Group: 2
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 1000 1000 9 10 2 5 10 10 5 5 ... |
| correct output |
|---|
| YES YES YES YES NO ... |
| user output |
|---|
| (empty) |
Test 7
Group: 2
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 1000 1000 5 7 9 9 3 7 8 10 ... |
| correct output |
|---|
| YES NO NO YES YES ... |
| user output |
|---|
| (empty) |
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 ... Truncated |
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 ... Truncated |
Test 10
Group: 3
Verdict: TIME LIMIT EXCEEDED
| 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: TIME LIMIT EXCEEDED
| 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: TIME LIMIT EXCEEDED
| 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: ACCEPTED
| input |
|---|
| 100000 1000 1000 1000 1000 1000 1000 1000 1000 1000 ... |
| correct output |
|---|
| YES YES YES YES YES ... |
| user output |
|---|
| YES YES YES YES YES ... Truncated |
Test 14
Group: 3
Verdict: ACCEPTED
| input |
|---|
| 100000 100000 1 100000 1 100000 1 100000 1 100000 ... |
| correct output |
|---|
| YES YES YES YES YES ... |
| user output |
|---|
| YES YES YES YES YES ... Truncated |
Test 15
Group: 3
Verdict: ACCEPTED
| input |
|---|
| 100000 100000 80971 98445 93046 96043 74840 94035 95931 96609 ... |
| correct output |
|---|
| NO NO NO NO NO ... |
| user output |
|---|
| NO NO NO NO NO ... Truncated |
Test 16
Group: 3
Verdict: ACCEPTED
| input |
|---|
| 100000 10000 6481 14350 69129 87600 6217 16462 4387 16625 ... |
| correct output |
|---|
| YES YES YES YES YES ... |
| user output |
|---|
| YES YES YES YES YES ... Truncated |
