QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#569633#8790. First BillionHTensorTL 329ms4904kbC++172.1kb2024-09-17 02:16:192024-09-17 02:16:20

Judging History

你现在查看的是最新测评结果

  • [2024-09-17 02:16:20]
  • 评测
  • 测评结果:TL
  • 用时:329ms
  • 内存:4904kb
  • [2024-09-17 02:16:19]
  • 提交

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 = 6400;

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: 100
Accepted
time: 1ms
memory: 3688kb

input:

10
386413329 88494216 245947398 316438989 192751270 204627269 65749456 3938400 150458676 345180997

output:

5 6 5 7 9 1 

result:

ok OK (n = 10)

Test #2:

score: 0
Accepted
time: 1ms
memory: 3672kb

input:

10
119486233 299942886 169540407 349937991 597883752 32230162 140514533 57341098 12602102 220520836

output:

5 6 8 5 2 9 

result:

ok OK (n = 10)

Test #3:

score: 0
Accepted
time: 0ms
memory: 4116kb

input:

14
384615281 84612238 83310504 54746763 142296081 56775470 128760350 343006424 177232390 214368720 67220468 21895072 16352717 224807522

output:

7 5 4 3 11 8 2 14 

result:

ok OK (n = 14)

Test #4:

score: 0
Accepted
time: 1ms
memory: 4008kb

input:

14
270208635 14270307 89661499 113578022 47687195 101043954 38775146 208193324 650676076 351701957 3427619 59535626 24230888 27009752

output:

7 8 5 7 11 13 14 9 

result:

ok OK (n = 14)

Test #5:

score: 0
Accepted
time: 20ms
memory: 4896kb

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 16 2 17 1 15 19 7 3 6 

result:

ok OK (n = 20)

Test #6:

score: 0
Accepted
time: 329ms
memory: 4904kb

input:

20
67858098 61231428 99398662 1883806 82465954 303619377 87516412 154956240 94872199 76508350 13276828 136541811 203282099 99160366 127539385 13364660 141176136 39751629 67888657 127707903

output:

10 19 20 10 15 18 16 6 9 2 7 

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

output:


result: