QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#630820#8790. First Billionqianchen06#TL 155ms31672kbC++201.6kb2024-10-11 20:32:332024-10-11 20:32:35

Judging History

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

  • [2024-10-11 20:32:35]
  • 评测
  • 测评结果:TL
  • 用时:155ms
  • 内存:31672kb
  • [2024-10-11 20:32:33]
  • 提交

answer

#pragma GCC optimize(2)
#pragma GCC optimize(3,"ofast","inline")
#include <bits/stdc++.h>
using namespace std;

#define ll long long

int n, a[110];
vector<int> v;
unordered_set<int> se;
unordered_map<int, int> from;
unordered_map<int, int> bel;
priority_queue<int, vector<int>, greater<int>> q;
priority_queue<int, vector<int>, greater<int>> qq;
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    q.emplace(0);
    se.emplace(0);
    for (int i = 1; i <= n; ++i)
    {
        while (!q.empty())
        {
            int tis = q.top();
            q.pop();
            qq.emplace(tis);

            int nex = tis + a[i];
            if (se.count(nex) && nex > 1e9)
                continue;
            if (nex == 1e9)
            {
                // end
                int p = i;
                from[nex] = bel[tis];
                bel[nex] = i;
                while (p)
                {
                    v.emplace_back(p);
                    int tp = from[nex];
                    nex -= a[p];
                    p = tp;
                }
                sort(v.begin(), v.end());
                cout << v.size() << " ";
                for (auto c : v)
                    cout << c << " ";
                return 0;
            }
            from[nex] = bel[tis];
            bel[nex] = i;
            qq.emplace(nex);
            se.emplace(nex);
        }
        swap(qq, q);
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3616kb

input:

10
386413329 88494216 245947398 316438989 192751270 204627269 65749456 3938400 150458676 345180997

output:

5 1 5 6 7 9 

result:

ok OK (n = 10)

Test #2:

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

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: 2ms
memory: 4760kb

input:

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

output:

7 1 6 7 9 10 12 13 

result:

ok OK (n = 14)

Test #4:

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

input:

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

output:

7 1 2 3 4 6 10 12 

result:

ok OK (n = 14)

Test #5:

score: 0
Accepted
time: 155ms
memory: 31672kb

input:

20
61638928 106712373 5946815 178135484 4937573 111395400 15504655 67139983 101814514 312223647 130341028 43244171 37671364 54108486 337181317 37924824 153793862 70383750 102917244 66984582

output:

10 4 5 8 9 10 11 12 13 14 18 

result:

ok OK (n = 20)

Test #6:

score: 0
Accepted
time: 53ms
memory: 17296kb

input:

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

output:

10 1 3 4 5 8 11 12 13 14 17 

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: