| Task: | Ryhmät |
| Sender: | Metabolix |
| Submission time: | 2025-09-26 23:07:09 +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.18 s | 1, 2, 3 | details |
| #2 | ACCEPTED | 0.15 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.28 s | 1, 2, 3 | details |
| #6 | TIME LIMIT EXCEEDED | -- | 2 | details |
| #7 | TIME LIMIT EXCEEDED | -- | 2 | details |
| #8 | ACCEPTED | 0.35 s | 2 | details |
| #9 | ACCEPTED | 0.17 s | 2, 3 | details |
| #10 | TIME LIMIT EXCEEDED | -- | 3 | details |
| #11 | TIME LIMIT EXCEEDED | -- | 3 | details |
| #12 | TIME LIMIT EXCEEDED | -- | 3 | details |
| #13 | TIME LIMIT EXCEEDED | -- | 3 | details |
| #14 | TIME LIMIT EXCEEDED | -- | 3 | details |
| #15 | TIME LIMIT EXCEEDED | -- | 3 | details |
| #16 | TIME LIMIT EXCEEDED | -- | 3 | details |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:109:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
109 | for (int i = 0; i < path.size() - 1; ++i) {
| ~~^~~~~~~~~~~~~~~~~Code
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <queue>
using namespace std;
#define a first
#define b second
struct Node {
int a, b;
int sink;
vector<int> sinks;
};
struct Sink {
int used, max_capacity;
vector<int> nodes;
};
int main() {
int node_count, test_count;
cin >> node_count >> test_count;
vector<Node> nodes(node_count);
for (int i = 0; i < node_count; ++i) {
cin >> nodes[i].a >> nodes[i].b;
}
map<int, vector<int>> nodes_start, nodes_ended;
for (int i = 0; i < node_count; ++i) {
nodes_start[nodes[i].a].push_back(i);
nodes_ended[nodes[i].b+1].push_back(i);
}
for (int t_ = 0; t_ < test_count; ++t_) {
for (auto& node : nodes) {
node.sink = 0;
node.sinks.clear();
}
int sink_count;
cin >> sink_count;
set<int> sink_values;
unordered_map<int, Sink> sinks;
for (int i = 0; i < sink_count; ++i) {
int value;
cin >> value;
sink_values.insert(value);
sinks[value].max_capacity += value;
}
auto nodes_start_iter = nodes_start.begin();
auto nodes_ended_iter = nodes_ended.begin();
unordered_set<int> nodes_active;
for (int sink: sink_values) {
while (nodes_start_iter != nodes_start.end() && nodes_start_iter->first <= sink) {
for (int node_index : nodes_start_iter->second) {
nodes_active.insert(node_index);
}
++nodes_start_iter;
}
while (nodes_ended_iter != nodes_ended.end() && nodes_ended_iter->first <= sink) {
for (int node_index : nodes_ended_iter->second) {
nodes_active.erase(node_index);
}
++nodes_ended_iter;
}
for (int node_index : nodes_active) {
nodes[node_index].sinks.push_back(sink);
sinks[sink].nodes.push_back(node_index);
}
}
// Ahne aloitus
for (int sink: sink_values) {
for (int node_index : sinks[sink].nodes) {
if (nodes[node_index].sink == 0) {
sinks[sink].used += 1;
nodes[node_index].sink = sink;
if (sinks[sink].used == sinks[sink].max_capacity) {
break;
}
}
}
}
// Vaihtoehtoiset reitit
bool changed = true;
while (changed) {
changed = false;
unordered_set<int> visited;
queue<vector<int>> bfs;
for (int i = 0; i < node_count; ++i) {
if (nodes[i].sink == 0 && !nodes[i].sinks.empty()) {
bfs.push({i});
}
}
while (!bfs.empty() && !changed) {
vector<int> path = bfs.front();
bfs.pop();
int last_node_index = path.back();
visited.insert(last_node_index);
for (int sink : nodes[last_node_index].sinks) {
if (sinks[sink].used < sinks[sink].max_capacity) {
changed = true;
for (int i = 0; i < path.size() - 1; ++i) {
nodes[path[i]].sink = nodes[path[i+1]].sink;
}
nodes[last_node_index].sink = sink;
sinks[sink].used += 1;
goto end_bfs;
}
}
for (int sink : nodes[last_node_index].sinks) {
if (sinks[sink].used == sinks[sink].max_capacity) {
for (int node_index : sinks[sink].nodes) {
if (nodes[node_index].sink == sink && !visited.count(node_index)) {
//find(path.begin(), path.end(), node_index) == path.end()) {
vector<int> new_path = path;
new_path.push_back(node_index);
bfs.push(new_path);
}
}
}
}
}
end_bfs:;
}
bool all_full = true;
for (int sink: sink_values) {
if (sinks[sink].used != sinks[sink].max_capacity) {
all_full = false;
break;
}
}
if (!all_full) {
cout << "NO\n";
} else {
cout << "YES\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: TIME LIMIT EXCEEDED
| 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: TIME LIMIT EXCEEDED
| 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: TIME LIMIT EXCEEDED
| 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: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 10000 6481 14350 69129 87600 6217 16462 4387 16625 ... |
| correct output |
|---|
| YES YES YES YES YES ... |
| user output |
|---|
| (empty) |
