QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#645661#6397. Master of Both IIIcrimsonsunset#TL 1827ms297964kbC++201.6kb2024-10-16 19:22:172024-10-16 19:22:17

Judging History

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

  • [2024-10-16 19:22:17]
  • 评测
  • 测评结果:TL
  • 用时:1827ms
  • 内存:297964kb
  • [2024-10-16 19:22:17]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
#define int ll
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

const int mod = 998244353;

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> w(n);
    for (int i = 0; i < n; ++i) cin >> w[i];
    vector<int> lol((1 << n), 1e18);
    lol[0] = 0;
    lol[1] = 0;
    set<pair<int, int>> cur;
    for (int i = 0; i < (1 << n); ++i) cur.insert({lol[i], i});
    while (cur.size()) {
        pair<int, int> lolll = *cur.begin();
        int mask = lolll.second;
        cur.erase(cur.begin());
        for (int i = 1; i < n; ++i) {
            int tmask = ((mask | ((mask << i) | (mask << i >> n))) & ((1 << n) - 1));
//            cout << mask << ' ' << i << ' ' << tmask << '\n';
            if (lol[tmask] > lol[mask] + w[i]) {
                cur.erase({lol[tmask], tmask});
                lol[tmask] = lol[mask] + w[i];
                cur.insert({lol[tmask], tmask});
            }
        }
    }
    for (int i = (1 << n) - 1; i >= 0; --i) {
        for (int j = 0; j < n; ++j) lol[i] = min(lol[i], lol[(i | (1 << j))]);
    }
    int ans = 0;
    for (int i = 1; i < (1 << n); ++i) {
//        cout << lol[i] << ' ';
        int x = 0;
        for (int j = 1; j < n; ++j) {
            if ((i >> j) & 1) {
                x += (1 << (n - j));
            }
        }
        ans += i * lol[x];
        ans %= mod;
    }
    cout << ans;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3532kb

input:

3
2 1 2

output:

45

result:

ok 1 number(s): "45"

Test #2:

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

input:

4
1919810 999999998 999999997 114114514

output:

152175989

result:

ok 1 number(s): "152175989"

Test #3:

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

input:

3
842160586 705327547 868243944

output:

78597628

result:

ok 1 number(s): "78597628"

Test #4:

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

input:

5
198327434 147392532 760837755 771109105 676721155

output:

751568230

result:

ok 1 number(s): "751568230"

Test #5:

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

input:

10
831766351 33417723 223739726 80131988 348810263 415437931 119999060 799356097 512022962 23197703

output:

308170104

result:

ok 1 number(s): "308170104"

Test #6:

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

input:

12
892965903 35291219 261557729 131390943 457251874 944586973 724767219 190756777 658923976 587806068 793999675 378390067

output:

964920873

result:

ok 1 number(s): "964920873"

Test #7:

score: 0
Accepted
time: 4ms
memory: 4788kb

input:

14
249132751 477356204 594343028 32906794 270726189 883801423 329535378 877124753 100792287 152414432 142520554 196476850 924736849 383197276

output:

796031217

result:

ok 1 number(s): "796031217"

Test #8:

score: 0
Accepted
time: 347ms
memory: 76812kb

input:

20
627365465 726842612 947302944 649244156 293375951 318148820 237155023 981487641 688151803 844901013 430309799 733877736 520864483 720366437 28746495 143052089 306590290 18586578 662663479 375430013

output:

179404754

result:

ok 1 number(s): "179404754"

Test #9:

score: 0
Accepted
time: 745ms
memory: 150812kb

input:

21
805448889 595358753 391340394 525130530 272725205 157594893 261894302 29704333 909085958 127205196 104570238 495437480 458664573 599968678 690908307 220500006 735062204 172834136 241126905 814694254 294923292

output:

260115885

result:

ok 1 number(s): "260115885"

Test #10:

score: 0
Accepted
time: 1827ms
memory: 297964kb

input:

22
983532313 168907597 985120947 845727304 401817563 702073670 841923182 372888321 835052818 409509378 73797974 256997223 101497367 919762407 912878630 297947923 723342631 32114398 409524923 253958495 441987041 591475412

output:

428320025

result:

ok 1 number(s): "428320025"

Test #11:

score: 0
Accepted
time: 802ms
memory: 150660kb

input:

21
11 15 20 22 23 41 78 144 266 522 1025 2051 4114 8206 16404 32788 65554 131084 262147 524308 1048583

output:

975218988

result:

ok 1 number(s): "975218988"

Test #12:

score: -100
Time Limit Exceeded

input:

22
5 7 13 23 33 35 74 144 274 518 1025 2050 4108 8210 16385 32771 65555 131076 262158 524305 1048593 2097169

output:

430862284

result: