QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#622389 | #8790. First Billion | BlackPanda | WA | 346ms | 40868kb | C++20 | 1.8kb | 2024-10-08 21:21:17 | 2024-10-08 21:21:18 |
Judging History
answer
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <map>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> c(N);
for (int i = 0; i < N; ++i) {
cin >> c[i];
}
const int64_t TARGET = 1e9;
const int K = 100000; // Limit the number of sums to keep
// Initialize sums
map<int64_t, vector<int>> sums;
sums[0] = {};
for (int i = 0; i < N; ++i) {
map<int64_t, vector<int>> next_sums = sums;
for (auto& [s, idx_list] : sums) {
int64_t s_new = s + c[i];
if (s_new > TARGET) continue;
if (s_new == TARGET) {
// Found the solution
idx_list.push_back(i + 1); // +1 because indices are 1-based
cout << idx_list.size();
for (int idx : idx_list) {
cout << " " << idx;
}
cout << endl;
return 0;
}
if (next_sums.find(s_new) == next_sums.end() || next_sums[s_new].size() > idx_list.size() + 1) {
vector<int> new_idx_list = idx_list;
new_idx_list.push_back(i + 1); // +1 because indices are 1-based
next_sums[s_new] = new_idx_list;
}
}
// Prune the next_sums if it exceeds size K
if (next_sums.size() > K) {
// Keep only K smallest sums
while (next_sums.size() > K) {
next_sums.erase(prev(next_sums.end()));
}
}
sums = move(next_sums);
}
// If we reach here, no exact sum was found
// Optionally, output an approximate solution or indicate no solution
cout << "0" << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3660kb
input:
10 386413329 88494216 245947398 316438989 192751270 204627269 65749456 3938400 150458676 345180997
output:
5 1 5 6 7 9
result:
ok OK (n = 10)
Test #2:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
10 119486233 299942886 169540407 349937991 597883752 32230162 140514533 57341098 12602102 220520836
output:
5 2 5 6 8 9
result:
ok OK (n = 10)
Test #3:
score: 0
Accepted
time: 2ms
memory: 4456kb
input:
14 384615281 84612238 83310504 54746763 142296081 56775470 128760350 343006424 177232390 214368720 67220468 21895072 16352717 224807522
output:
7 1 6 7 9 10 12 13
result:
ok OK (n = 14)
Test #4:
score: 0
Accepted
time: 0ms
memory: 3896kb
input:
14 270208635 14270307 89661499 113578022 47687195 101043954 38775146 208193324 650676076 351701957 3427619 59535626 24230888 27009752
output:
7 1 2 3 4 6 10 12
result:
ok OK (n = 14)
Test #5:
score: 0
Accepted
time: 56ms
memory: 33952kb
input:
20 61638928 106712373 5946815 178135484 4937573 111395400 15504655 67139983 101814514 312223647 130341028 43244171 37671364 54108486 337181317 37924824 153793862 70383750 102917244 66984582
output:
10 4 5 8 9 10 11 12 13 14 18
result:
ok OK (n = 20)
Test #6:
score: 0
Accepted
time: 33ms
memory: 20508kb
input:
20 67858098 61231428 99398662 1883806 82465954 303619377 87516412 154956240 94872199 76508350 13276828 136541811 203282099 99160366 127539385 13364660 141176136 39751629 67888657 127707903
output:
10 1 3 4 5 8 11 12 13 14 17
result:
ok OK (n = 20)
Test #7:
score: -100
Wrong Answer
time: 346ms
memory: 40868kb
input:
24 17125795 281143405 10375259 196293002 158174864 34520650 52919232 87393970 99085271 62281508 67168428 55174991 54533464 51393059 89276370 41441658 72793517 30466999 73758332 97064918 111541434 142047546 12934221 101092107
output:
0
result:
wrong answer need sum 1000000000, got sum 0