Submission #1232554

#TimeUsernameProblemLanguageResultExecution timeMemory
1232554nibertNile (IOI24_nile)C++20
0 / 100
17 ms2624 KiB
#include "bits/stdc++.h" #include "nile.h" using namespace std; vector<long long> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E) { const int MAX_W = 10; const int MAX_D = 10; int N = W.size(), Q = E.size(); // Group artifacts by weight (1 to 10) vector<vector<pair<int, int>>> weight_buckets(MAX_W + 1); for (int i = 0; i < N; ++i) { weight_buckets[W[i]].emplace_back(A[i], B[i]); } // For each D = 1 to 10, precompute minimum cost vector<long long> cost_for_d(MAX_D + 1, 0); for (int D = 1; D <= MAX_D; ++D) { vector<vector<int>> solo_costs(MAX_W + 1); // A[i] values vector<multiset<int>> pair_costs(MAX_W + 1); // B[i] values // Load artifacts into solo_costs and pair_costs for (int w = 1; w <= MAX_W; ++w) { for (auto [a, b] : weight_buckets[w]) { solo_costs[w].push_back(a); pair_costs[w].insert(b); } } long long total = 0; // Try to pair artifacts from weights w and w+dx (dx <= D) for (int w = 1; w <= MAX_W; ++w) { for (int dw = 0; dw <= D; ++dw) { int w2 = w + dw; if (w2 > MAX_W) continue; if (w == w2) { // Pair within same group while (pair_costs[w].size() >= 2) { auto it1 = pair_costs[w].begin(); auto it2 = next(it1); total += *it1 + *it2; pair_costs[w].erase(it1); pair_costs[w].erase(pair_costs[w].begin()); } } else { while (!pair_costs[w].empty() && !pair_costs[w2].empty()) { auto it1 = pair_costs[w].begin(); auto it2 = pair_costs[w2].begin(); total += *it1 + *it2; pair_costs[w].erase(it1); pair_costs[w2].erase(it2); } } } } // Send the remaining artifacts alone for (int w = 1; w <= MAX_W; ++w) { for (int b : pair_costs[w]) { int index = solo_costs[w].size() - pair_costs[w].size(); total += solo_costs[w][index]; // A[i] for unpaired item } } cost_for_d[D] = total; } // Answer queries vector<long long> result(Q); for (int i = 0; i < Q; ++i) { result[i] = cost_for_d[E[i]]; } return result; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...