QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#561337 | #8790. First Billion | peter | TL | 5ms | 13904kb | C++14 | 1023b | 2024-09-12 21:54:48 | 2024-09-12 21:54:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn=105;
const int mod=3e6+19;
const int ed=1e9;
int a[maxn];
bitset<mod> b[maxn];
vector<int> res;
int main(){
mt19937 rnd(time(0));
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
b[0][0]=1;
for(int i=1;i<=n;i++){
b[i]=b[i-1]|(b[i-1]<<(a[i]%mod));
if(a[i]%mod) b[i]=b[i]|(b[i-1]>>(mod-(a[i]%mod)));
// for(int j=0;j<mod;j++){
// if(b[i][j]) printf("%d ",j);
// }
// puts("");
}
while(1){
int now=(ed%mod);
res.clear();
for(int i=n;i>=1;i--){
if(b[i-1][now]&&b[i-1][(now-(a[i]%mod)+mod)%mod]&&(rnd()&1)){
res.push_back(i);
now=(now-(a[i]%mod)+mod)%mod;
}else if(b[i-1][(now-(a[i]%mod)+mod)%mod]){
res.push_back(i);
now=(now-(a[i]%mod)+mod)%mod;
}
}
int sum=0;
for(int x : res) sum+=a[x];
if(sum==1e9){
printf("%d ",(int)res.size());
for(int x : res) printf("%d ",x);
puts("");
return 0;
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9072kb
input:
10 386413329 88494216 245947398 316438989 192751270 204627269 65749456 3938400 150458676 345180997
output:
5 10 8 4 3 2
result:
ok OK (n = 10)
Test #2:
score: 0
Accepted
time: 0ms
memory: 9104kb
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: 0ms
memory: 11084kb
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: 5ms
memory: 11624kb
input:
14 270208635 14270307 89661499 113578022 47687195 101043954 38775146 208193324 650676076 351701957 3427619 59535626 24230888 27009752
output:
7 14 13 11 9 8 7 5
result:
ok OK (n = 14)
Test #5:
score: 0
Accepted
time: 0ms
memory: 13272kb
input:
20 61638928 106712373 5946815 178135484 4937573 111395400 15504655 67139983 101814514 312223647 130341028 43244171 37671364 54108486 337181317 37924824 153793862 70383750 102917244 66984582
output:
10 20 19 17 16 15 7 6 3 2 1
result:
ok OK (n = 20)
Test #6:
score: 0
Accepted
time: 3ms
memory: 13904kb
input:
20 67858098 61231428 99398662 1883806 82465954 303619377 87516412 154956240 94872199 76508350 13276828 136541811 203282099 99160366 127539385 13364660 141176136 39751629 67888657 127707903
output:
10 20 19 18 16 15 10 9 7 6 2
result:
ok OK (n = 20)
Test #7:
score: -100
Time Limit Exceeded
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