Task: | Ryhmät |
Sender: | Metabolix |
Submission time: | 2025-10-05 18:11:50 +0300 |
Language: | C++ (C++20) |
Status: | READY |
Result: | 25 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 10 |
#2 | ACCEPTED | 15 |
#3 | RUNTIME ERROR | 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.01 s | 1, 2, 3 | details |
#5 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#6 | ACCEPTED | 0.03 s | 2 | details |
#7 | ACCEPTED | 0.05 s | 2 | details |
#8 | ACCEPTED | 0.10 s | 2 | details |
#9 | ACCEPTED | 0.01 s | 2, 3 | details |
#10 | ACCEPTED | 0.26 s | 3 | details |
#11 | ACCEPTED | 0.22 s | 3 | details |
#12 | ACCEPTED | 0.17 s | 3 | details |
#13 | ACCEPTED | 0.09 s | 3 | details |
#14 | RUNTIME ERROR | 0.41 s | 3 | details |
#15 | RUNTIME ERROR | 0.43 s | 3 | details |
#16 | ACCEPTED | 0.41 s | 3 | details |
Compiler report
input/code.cpp: In member function 'void mybits::operator|=(const mybits&)': input/code.cpp:27:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::array<std::bitset<512>, 196>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 27 | for (int i = 0; i < data.size(); i++) { | ~~^~~~~~~~~~~~~ input/code.cpp: In member function 'void mybits::operator^=(const mybits&)': input/code.cpp:32:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::array<std::bitset<512>, 196>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 32 | for (int i = 0; i < data.size(); i++) { | ~~^~~~~~~~~~~~~ input/code.cpp: In member function 'bool mybits::poista(const mybits&, int)': input/code.cpp:44:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::array<std::bitset<512>, 196>::size_type' {aka 'long unsigned int'} [-Wsign...
Code
#include <iostream> #include <queue> #include <vector> #include <map> #include <algorithm> #include <array> #include <unordered_set> #include <set> #include <bitset> using namespace std; struct Toive { int alku, loppu, indeksi; }; struct mybits { array<bitset<512>, 100001 / 512 + 1> data; bool set(int i, bool value) { int idx = i / 512; int bit = i % 512; bool was_set = data[idx][bit]; data[idx][bit] = value; return was_set; } void operator|=(const mybits& other) { for (int i = 0; i < data.size(); i++) { data[i] |= other.data[i]; } } void operator^=(const mybits& other) { for (int i = 0; i < data.size(); i++) { data[i] ^= other.data[i]; } } int count() const { int total = 0; for (const auto& b : data) { total += b.count(); } return total; } bool poista(const mybits& other, int määrä) { for (int i = 0; i < data.size() && määrä; i++) { auto a = data[i] & other.data[i]; auto c = a.count(); for (int shl_min = 0, shl_max = 512; c > määrä;) { int shl = (shl_min + shl_max) / 2; auto a2 = (a << shl) >> shl; auto c2 = a2.count(); if (c2 == määrä) { data[i] ^= a2; return true; } if (c2 > määrä) { shl_min = shl; } else { shl_max = shl; } } määrä -= c; data[i] ^= a; } return määrä == 0; } }; int main() { ios::sync_with_stdio(false); int n, t; cin >> n >> t; vector<pair<int, int>> toiveet_loppu_alku(n), toiveet_alku_indeksi(n); for (int i = 0; i < n; i++) { cin >> toiveet_loppu_alku[i].second >> toiveet_loppu_alku[i].first; } ranges::sort(toiveet_loppu_alku); for (int i = 0; i < n; i++) { toiveet_alku_indeksi[i] = {toiveet_loppu_alku[i].second, i}; } ranges::sort(toiveet_alku_indeksi); vector<bool> tulokset(t, true); vector<array<int, 3>> vaiheet; mybits kaikki_vapaana; for (auto &a: kaikki_vapaana.data) { a.set(); } vector<mybits> vapaat(t, kaikki_vapaana); for (int testi = 0; testi < t; testi++) { int ryhmien_määrä; cin >> ryhmien_määrä; map<int, int> ryhmät; for (int i = 0; i < ryhmien_määrä; i++) { int ryhmän_koko; cin >> ryhmän_koko; ryhmät[ryhmän_koko] += ryhmän_koko; } for (auto &[koko, lapsimäärä] : ryhmät) { vaiheet.push_back({koko, lapsimäärä, testi}); } } ranges::sort(vaiheet); auto toive_iter = toiveet_alku_indeksi.begin(); set<int> toiveet_kesken; mybits toiveet_bits; for (auto &[koko, lapsimäärä, testi] : vaiheet) { if (tulokset[testi] == false) { continue; } while (toive_iter != toiveet_alku_indeksi.end() && toive_iter->first <= koko) { int indeksi = toive_iter->second; toiveet_kesken.insert(indeksi); toiveet_bits.set(indeksi, true); toive_iter++; } while (!toiveet_kesken.empty() && toiveet_loppu_alku[*toiveet_kesken.begin()].first < koko) { int indeksi = *toiveet_kesken.begin(); toiveet_kesken.erase(toiveet_kesken.begin()); toiveet_bits.set(indeksi, false); } if (!vapaat[testi].poista(toiveet_bits, lapsimäärä)) { tulokset[testi] = false; } } for (auto tulos : tulokset) { if (tulos) { cout << "YES\n"; } else { cout << "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 ... |
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 ... |
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: ACCEPTED
input |
---|
100000 1000 774 778 363 852 309 668 261 459 ... |
correct output |
---|
YES YES YES YES YES ... |
user output |
---|
YES YES YES YES YES ... |
Test 11
Group: 3
Verdict: ACCEPTED
input |
---|
100000 1000 1233 1914 901 3963 1277 4293 1083 1599 ... |
correct output |
---|
NO NO YES NO NO ... |
user output |
---|
NO NO YES NO NO ... |
Test 12
Group: 3
Verdict: ACCEPTED
input |
---|
100000 1000 1970 8631 4606 5797 6317 8162 8204 8789 ... |
correct output |
---|
NO NO NO NO NO ... |
user output |
---|
NO NO NO NO NO ... |
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 ... |
Test 14
Group: 3
Verdict: RUNTIME ERROR
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: RUNTIME ERROR
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: 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 ... |