QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#676470 | #8790. First Billion | caustique | TL | 738ms | 4924kb | C++17 | 2.1kb | 2024-10-25 21:41:07 | 2024-10-25 21:41:07 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define SZ(a) (int)(a).size()
#define ALL(a) (a).begin(), (a).end()
using namespace std;
long long sum(const vector<int>& a, const vector<int>& idx) {
long long sum = 0;
REP(i, SZ(idx)) {
sum += a[idx[i] - 1];
}
return sum;
}
bool isprime(int n) {
if (n <= 1) return false;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
vector<int> run(const vector<int>& a, const int M) {
const int n = SZ(a);
vector<vector<bool>> dp(n + 1, vector<bool>(M));
vector<vector<int>> pr(n + 1, vector<int>(M, -1));
dp[0][0] = true;
REP(i, n) {
REP(j, M) {
if (!dp[i][j]) {
continue;
}
dp[i + 1][j] = true;
pr[i + 1][j] = j;
dp[i + 1][(j + a[i]) % M] = true;
pr[i + 1][(j + a[i]) % M] = j;
}
}
const int SUM = 1e9;
vector<int> res;
int cur = SUM % M;
for (int i = n; i > 0; i--) {
int prv = pr[i][cur];
if (prv != cur) {
res.push_back(i);
}
cur = prv;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
REP(i, n) cin >> a[i];
for (int M = 1000; ; M++) {
if (isprime(M)) {
vector<int> ids = run(a, M);
if (sum(a, ids) == 1'000'000'000) {
cout << SZ(ids) << '\n';
for (int id : ids) cout << id << ' ';
cout << '\n';
return 0;
}
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3852kb
input:
10 386413329 88494216 245947398 316438989 192751270 204627269 65749456 3938400 150458676 345180997
output:
5 9 7 6 5 1
result:
ok OK (n = 10)
Test #2:
score: 0
Accepted
time: 1ms
memory: 3852kb
input:
10 119486233 299942886 169540407 349937991 597883752 32230162 140514533 57341098 12602102 220520836
output:
5 10 7 4 3 1
result:
ok OK (n = 10)
Test #3:
score: 0
Accepted
time: 1ms
memory: 3596kb
input:
14 384615281 84612238 83310504 54746763 142296081 56775470 128760350 343006424 177232390 214368720 67220468 21895072 16352717 224807522
output:
7 14 11 8 5 4 3 2
result:
ok OK (n = 14)
Test #4:
score: 0
Accepted
time: 1ms
memory: 3840kb
input:
14 270208635 14270307 89661499 113578022 47687195 101043954 38775146 208193324 650676076 351701957 3427619 59535626 24230888 27009752
output:
7 12 10 6 4 3 2 1
result:
ok OK (n = 14)
Test #5:
score: 0
Accepted
time: 82ms
memory: 3728kb
input:
20 61638928 106712373 5946815 178135484 4937573 111395400 15504655 67139983 101814514 312223647 130341028 43244171 37671364 54108486 337181317 37924824 153793862 70383750 102917244 66984582
output:
10 18 14 13 12 11 10 9 8 5 4
result:
ok OK (n = 20)
Test #6:
score: 0
Accepted
time: 75ms
memory: 3728kb
input:
20 67858098 61231428 99398662 1883806 82465954 303619377 87516412 154956240 94872199 76508350 13276828 136541811 203282099 99160366 127539385 13364660 141176136 39751629 67888657 127707903
output:
10 17 14 13 12 11 8 5 4 3 1
result:
ok OK (n = 20)
Test #7:
score: 0
Accepted
time: 738ms
memory: 4924kb
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:
12 24 21 16 14 12 11 9 8 7 6 2 1
result:
ok OK (n = 24)
Test #8:
score: 0
Accepted
time: 514ms
memory: 4624kb
input:
24 70224368 148769600 36654748 23404220 15009825 57449487 46896672 6065662 10377031 133719710 23220853 184445684 8462667 88501546 155244839 229323557 140109402 52520271 78995771 75721556 87987586 118427778 107013825 101453342
output:
12 24 22 18 16 15 14 13 9 8 6 4 2
result:
ok OK (n = 24)
Test #9:
score: -100
Time Limit Exceeded
input:
28 122321206 60841271 22767116 183943582 6247754 32767541 19129802 21313874 144503909 59360441 12259051 19044256 50267333 25766572 133411289 32253746 102412217 46186594 55413161 39907615 52325783 86862071 185310732 138228874 22000146 149813853 98156445 77183766