QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#569631 | #8790. First Billion | HTensor | TL | 0ms | 0kb | C++17 | 2.1kb | 2024-09-17 02:13:45 | 2024-09-17 02:13:46 |
answer
#include <bits/stdc++.h>
#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 = 3e5;
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(mod + 1, vector<int>());
ans.clear();
int sum = 0;
for(int i = 1; i <= n; i++) {
vector<int> mdf(mod, 0);
for(int j = mod - 1; j; j--) {
if(dp[j].size() && !mdf[j]) {
if((j + a[i].first) % mod == 0) {
ans = dp[j];
ans.push_back(a[i].second);
goto end;
} else {
int id = (j + a[i].first) % mod;
dp[id] = dp[j];
dp[id].push_back(a[i].second);
mdf[id] = 1;
}
}
}
dp[a[i].first] = vector<int>{a[i].second};
}
end:
for(auto i : ans) {
sum += ori[i];
}
if(sum != (long long)1e9) {
return false;
}
return true;
};
while(!check()) {
continue;
}
cout << ans.size() << " ";
for(auto i : ans) {
cout << i << " ";
}
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
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
10 386413329 88494216 245947398 316438989 192751270 204627269 65749456 3938400 150458676 345180997