QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#570748 | #8790. First Billion | HTensor | WA | 2ms | 6780kb | C++17 | 3.2kb | 2024-09-17 17:32:03 | 2024-09-17 17:32:05 |
Judging History
answer
#include<iostream>
#include<vector>
#include<algorithm>
#include<random>
#include<array>
#include<cassert>
#define dd(x) cout << #x << "\n"
#define d(x) cout << #x << ": " << x << "\n"
using namespace std;
#define int long long
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vii = vector<vector<int>>;
using a3 = array<int, 3>;
using ll = long long;
// const int inf = 0x3f3f3f3f3f3f3f3fLL;
const int mod = 1e4;
void solve() {
int n; cin >> n;
vector<int> ori(n + 1);
vector<pair<int, int>> a(n + 1);
for(int i = 1; i <= n; i++) {
cin >> ori[i];
a[i].first = ori[i] % mod;
a[i].second = i;
}
if(n == 2) {
cout << (ll) 1e9 << "\n";
return ;
}
vector<int> ans;
mt19937 rng(19260817);
auto check = [&]() {
shuffle(a.begin() + 1, a.end(), rng);
vector dp(n + 1, vector<int> (mod + 1));
vector fr(n + 1, vector<pair<int, int>>(mod + 1));
vector ch(n + 1, vector<int> (mod + 1));
ans.clear();
int sum = 0;
auto positive = [](int x) {
return (x % mod + mod) % mod;
};
for(int i = 1; i <= n; i++) {
for(int j = 0; j < mod; j++) {
int last = positive(j - a[i].first);
if(dp[i - 1][j]) {
dp[i][j] = dp[i - 1][j];
fr[i][j] = fr[i - 1][j];
ch[i][j] = ch[i - 1][j];
} else if(dp[i - 1][last]) {
dp[i][j] = dp[i - 1][last];
fr[i][j] = {i - 1, last};
ch[i][j] = i;
}
}
if(dp[i][0]) {
// cout << i << endl;
auto [ii, ij] = pair(i, 0LL);
// auto [ii, ij] = fr[i][0];
while(pair(ii, ij) != pair(0LL, 0LL)) {
ans.push_back(a[ch[ii][ij]].second);
int nii = fr[ii][ij].first, nij = fr[ii][ij].second;
ii = nii, ij = nij;
}
break;
}
if(!dp[i][a[i].first]) {
dp[i][a[i].first] = 1;
ch[i][a[i].first] = i;
}
}
for(auto pp : ans) {
sum += ori[pp];
cout << pp << " ";
}
cout << "\n";
if(sum % mod) assert(false);
if(sum != (long long)1e9) {
return false;
}
return true;
};
while(!check()) {
// assert(false);
continue;
}
cout << ans.size() << " ";
for(auto pp : ans) {
cout << pp << " ";
}
cout << "\n";
}
signed main() {
// ios::sync_with_stdio(false); cin.tie(0);
int T = 1;
while(T--) solve();
return 0;
}
/*
10
386413329 88494216 245947398 316438989 192751270 204627269 65749456 3938400 150458676 345180997
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
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 6780kb
input:
10 386413329 88494216 245947398 316438989 192751270 204627269 65749456 3938400 150458676 345180997
output:
1 9 7 5 6 5 1 9 7 5 6
result:
wrong answer need sum 1000000000, got sum 150458676