# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1102673 |
2024-10-18T15:27:40 Z |
xnqs |
Topical (NOI23_topical) |
C++17 |
|
1000 ms |
174920 KB |
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <numeric>
struct Module {
int n;
std::vector<int> req;
std::vector<int> add;
Module(int n = 0): n(n) {
req.assign(n, 0);
add.assign(n, 0);
}
};
struct TrieNode {
std::vector<int> idx;
int pfx_cnt = 0;
std::map<int, TrieNode*> next;
~TrieNode() {
for (auto& [key, val] : next) {
if (val) {
delete val;
}
}
next.clear();
}
};
int x, k;
std::vector<Module> arr;
TrieNode* root = new TrieNode;
void add_word(TrieNode* root, const std::vector<int>& word, int val) {
for (int i = 0; i < k; i++) {
if (!root->next[word[i]]) {
root->next[word[i]] = new TrieNode;
}
root = root->next[word[i]];
++root->pfx_cnt;
}
root->idx.emplace_back(val);
}
int search(TrieNode* root, const std::vector<int64_t>& cap, std::vector<int64_t>& add, int pos = 0) {
if (pos == k) {
for (int i = 0; i < k; i++) {
for (const auto& j : root->idx) {
add[i] += arr[j].add[i];
}
}
int ret = (int)root->idx.size();
root->pfx_cnt -= root->idx.size();
root->idx.clear();
return ret;
}
int ret = 0;
for (auto it = root->next.begin(); it != root->next.end();) {
auto [key, node] = *it;
if (key > cap[pos]) {
break;
}
int tmp = search(node, cap, add, pos+1);
ret += tmp;
root->pfx_cnt -= tmp;
if (node->pfx_cnt <= 0) {
it = root->next.erase(it);
}
else {
++it;
}
}
return ret;
}
void solve_k1() {
std::sort(arr.begin(), arr.end(), [](const Module& a, const Module& b) {
return a.req[0] < b.req[0];
});
int ans = 0;
int64_t curr_skill = 0;
for (const auto& it : arr) {
int req = it.req[0];
int add = it.add[0];
if (curr_skill < req) {
break;
}
++ans;
curr_skill += add;
}
std::cout << ans << "\n";
}
void solve_not_legit_at_all() {
std::vector<int> idx(x);
std::iota(idx.begin(),idx.end(),0);
std::sort(idx.begin(), idx.end(), [&](int a, int b) {
return arr[a].req[0] < arr[b].req[0];
});
int ans = 0;
std::vector<int64_t> cap(k,0);
while (!arr.empty()) {
std::vector<int> new_idx;
int old_ans = ans;
for (const auto& i : idx) {
bool ok = 1;
for (int j = 0; j < k; j++) {
if (arr[i].req[j] > cap[j]) {
ok = 0;
break;
}
}
if (!ok) {
new_idx.emplace_back(i);
continue;
}
ans += 1;
for (int j = 0; j < k; j++) {
cap[j] += arr[i].add[j];
}
}
if (old_ans==ans) {
break;
}
idx = new_idx;
}
std::cout << ans << "\n";
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
std::cin >> x >> k;
arr.reserve(x);
for (int i = 0; i < x; i++) {
arr.emplace_back(k);
for (int j = 0; j < k; j++) {
std::cin >> arr[i].req[j];
}
}
for (int i = 0; i < x; i++) {
for (int j = 0; j < k; j++) {
std::cin >> arr[i].add[j];
}
}
if (k==1) {
solve_k1();
return 0;
}
if (k>=50) {
solve_not_legit_at_all();
return 0;
}
for (int i = 0; i < x; i++) {
add_word(root, arr[i].req, i);
}
std::vector<int64_t> cap(k, 0);
int ans = 0;
while (1) {
std::vector<int64_t> add(k, 0);
int nodes = search(root, cap, add);
if (!nodes) {
break;
}
ans += nodes;
for (int i = 0; i < k; i++) {
cap[i] += add[i];
}
}
std::cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
105 ms |
15964 KB |
Output is correct |
5 |
Correct |
139 ms |
15944 KB |
Output is correct |
6 |
Correct |
111 ms |
15944 KB |
Output is correct |
7 |
Correct |
80 ms |
15944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
2 ms |
336 KB |
Output is correct |
8 |
Correct |
2 ms |
508 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
3 ms |
336 KB |
Output is correct |
11 |
Correct |
3 ms |
336 KB |
Output is correct |
12 |
Correct |
3 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
5 ms |
1628 KB |
Output is correct |
4 |
Correct |
38 ms |
12196 KB |
Output is correct |
5 |
Correct |
39 ms |
12112 KB |
Output is correct |
6 |
Correct |
609 ms |
117836 KB |
Output is correct |
7 |
Correct |
623 ms |
117856 KB |
Output is correct |
8 |
Correct |
592 ms |
117832 KB |
Output is correct |
9 |
Correct |
536 ms |
117664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
105 ms |
15964 KB |
Output is correct |
5 |
Correct |
139 ms |
15944 KB |
Output is correct |
6 |
Correct |
111 ms |
15944 KB |
Output is correct |
7 |
Correct |
80 ms |
15944 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
2 ms |
336 KB |
Output is correct |
15 |
Correct |
2 ms |
508 KB |
Output is correct |
16 |
Correct |
2 ms |
336 KB |
Output is correct |
17 |
Correct |
3 ms |
336 KB |
Output is correct |
18 |
Correct |
3 ms |
336 KB |
Output is correct |
19 |
Correct |
3 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
5 ms |
1628 KB |
Output is correct |
23 |
Correct |
38 ms |
12196 KB |
Output is correct |
24 |
Correct |
39 ms |
12112 KB |
Output is correct |
25 |
Correct |
609 ms |
117836 KB |
Output is correct |
26 |
Correct |
623 ms |
117856 KB |
Output is correct |
27 |
Correct |
592 ms |
117832 KB |
Output is correct |
28 |
Correct |
536 ms |
117664 KB |
Output is correct |
29 |
Correct |
130 ms |
8276 KB |
Output is correct |
30 |
Correct |
130 ms |
8276 KB |
Output is correct |
31 |
Execution timed out |
1090 ms |
174920 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |