QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#798447 | #8790. First Billion | piaoyun# | WA | 21ms | 21456kb | C++20 | 1.4kb | 2024-12-04 13:50:19 | 2024-12-04 13:50:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6;
int N,M,K,Q;
int a[101];
pair<int,int> pre[2][MAXN];
bool dp[2][MAXN];
void prepare(){
cin >> N;
for(int i = 1; i <= N; i++){
cin >> a[i];
}
// random_shuffle(a + 1, a + 1 + N);
dp[0][0] = 1;
for(int i = 0; i < N; i++){
int w = i & 1;
int val = a[N - i] % MAXN;
for(int k = 0; k < MAXN; k++){
dp[w ^ 1][k] = dp[w][k];
pre[w ^ 1][k] = pre[w][k];
}
for(int k = 0; k < MAXN; k++){
if(!dp[w][k]) continue;
int tar = k + val;
if(tar >= MAXN) tar -= MAXN;
if(tar == 0){
vector<int> ans;
ans.push_back(N - i);
int loc = k;
while(loc){
ans.push_back(pre[w][loc].second);
loc = pre[w][loc].first;
}
cout << ans.size() << " ";
sort(ans.begin(), ans.end());
for(auto x : ans){
cout << x << " ";
}
cout << "\n";
return;
}
if(dp[w ^ 1][tar]) continue;
dp[w ^ 1][tar] = 1;
pre[w ^ 1][tar] = pair(k, N - i);
}
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int T = 1;
// cin >> T;
while(T--){
prepare();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 12ms
memory: 21208kb
input:
10 386413329 88494216 245947398 316438989 192751270 204627269 65749456 3938400 150458676 345180997
output:
5 2 3 4 8 10
result:
ok OK (n = 10)
Test #2:
score: 0
Accepted
time: 21ms
memory: 21252kb
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: 19ms
memory: 21448kb
input:
14 384615281 84612238 83310504 54746763 142296081 56775470 128760350 343006424 177232390 214368720 67220468 21895072 16352717 224807522
output:
7 2 3 4 5 8 11 14
result:
ok OK (n = 14)
Test #4:
score: 0
Accepted
time: 19ms
memory: 21412kb
input:
14 270208635 14270307 89661499 113578022 47687195 101043954 38775146 208193324 650676076 351701957 3427619 59535626 24230888 27009752
output:
7 5 7 8 9 11 13 14
result:
ok OK (n = 14)
Test #5:
score: -100
Wrong Answer
time: 19ms
memory: 21456kb
input:
20 61638928 106712373 5946815 178135484 4937573 111395400 15504655 67139983 101814514 312223647 130341028 43244171 37671364 54108486 337181317 37924824 153793862 70383750 102917244 66984582
output:
8 5 6 10 12 14 15 16 20
result:
wrong answer need sum 1000000000, got sum 968000000