本題是互動題,不用引入任何標頭檔,程式碼請勿輸入或輸出任何東西。如果你輸入了任何東西可能會導致各種不可預期的結果。
5 2 2 4 3 1 5 1 4 1 5
本題沒有輸出
以下是一個可以編譯(但一定不會答對)的範例程式碼:
#include <vector>
bool compare_subsets(const std::vector<int>& a, const std::vector<int>& b);
namespace {
// 如果需要,你可以在這裡宣告全域變數
int len;
}
void init(int n) {
len = n;
}
std::vector<int> range_MWIS_query(int l, int r) {
return {r};
}
以下是範例 grader。
grader 輸出如題本敘述。
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <cassert>
// Functions to be implemented in the solution.
void init(int n);
std::vector <int> range_MWIS_query(int l, int r);
namespace {
long long n, q;
long long w[2002];
long long query_left[2002], query_right[2002];
long long query_count, Q_init, Q_query;
bool vis[2002];
std::vector<int> sol[2002];
void wrong_answer(const std::string &msg) {
std::cout << "Wrong Answer: " << msg << std::endl;
exit(0);
}
void check_valid_set(const std::vector<int> &a) {
for (int id : a) {
if (!(1 <= id && id <= n))
wrong_answer("Invalid vertex number: " + std::to_string(id));
if (vis[id])
wrong_answer("Duplicated vertex number: " + std::to_string(id));
vis[id] = true;
}
for (int id : a)
vis[id] = false;
}
long long get_subset_sum(const std::vector <int> a) {
long long res = 0;
for (int id : a)
res += w[id];
return res;
}
}
bool compare_subsets(const std::vector<int>& a, const std::vector<int>& b) {
check_valid_set(a);
check_valid_set(b);
return get_subset_sum(a) < get_subset_sum(b);
}
int main() {
std::cin >> n >> q;
for (int i = 1; i <= n; ++i) {
std::cin >> w[i];
}
for (int i = 1; i <= q; ++i) {
std::cin >> query_left[i] >> query_right[i];
}
init(n);
Q_init = (query_count + n - 1) / n;
query_count = 0;
for (int i = 1; i <= q; ++i) {
sol[i] = range_MWIS_query(query_left[i], query_right[i]);
Q_query = std::max(Q_query, query_count);
query_count = 0;
}
for (int i = 1; i <= q; ++i) {
std::cout << (int)sol[i].size() << std::endl;
for (int j = 0; j < (int)sol[i].size(); ++j) {
if (j > 0)
std::cout << " ";
std::cout << sol[i][j];
}
std::cout << std::endl;
}
std::cout << "Accepted: " << Q_init << " " << Q_query << std::endl;
return 0;
}
No. | Testdata Range | Score |
---|---|---|
1 | 0~10 | 16 |
2 | 11~20 | 11 |
3 | 0~50 | 73 |