QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#605717 | #6397. Master of Both III | lqh2024# | TL | 1833ms | 36008kb | C++17 | 1.8kb | 2024-10-02 19:02:15 | 2024-10-02 19:02:16 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define int long long
using i64 = long long;
mt19937_64 rd(time(0));
template <class K, class C = less<>> using paring_heap = __gnu_pbds::priority_queue<K, C>;
template <class K> using rb_tree = tree<K, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T, class ... A> void debug(const T & t, const A & ... a) { cerr << "[" << t, ((cerr << ", " << a), ...), cerr << "]\n"; }
const i64 mod = [](bool n) { return n ? 998244353 : 1e9 + 7; } (1);
void QAQ() {
int n;
cin >> n;
vector<int> a(n);
vector<int> dp(1ll << n, 4e18);
dp[0] = dp[1] = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (i) {
auto dpn = dp;
int t = n - i;
for (int sta = 0; sta < (1ll << n); sta++) {
int lst = sta;
for (int j = 1; j < n; j++) {
int m1 = lst & ((1ll << n - t) - 1), m2 = lst ^ m1;
int msk = lst | (m1 << t) | (m2 >> n - t) | (1ll << t);
dpn[msk] = min(dp[sta] + a[i] * j, dpn[msk]);
lst = msk;
}
}
swap(dpn, dp);
}
}
int ans = 0;
for (int sta = (1ll << n) - 1; ~sta; sta--) {
for (int i = 0; i < n; i++) {
if ((sta >> i & 1) == 0) {
dp[sta] = min(dp[sta], dp[sta ^ (1ll << i)]);
}
}
(ans += sta * dp[sta]) %= mod;
}
cout << ans << "\n";
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
int t = 1;
// cin >> t;
for (cout << fixed << setprecision(12); t--; QAQ());
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3680kb
input:
3 2 1 2
output:
45
result:
ok 1 number(s): "45"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3716kb
input:
4 1919810 999999998 999999997 114114514
output:
152175989
result:
ok 1 number(s): "152175989"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
3 842160586 705327547 868243944
output:
78597628
result:
ok 1 number(s): "78597628"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
5 198327434 147392532 760837755 771109105 676721155
output:
751568230
result:
ok 1 number(s): "751568230"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3704kb
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: 2ms
memory: 3976kb
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: 3ms
memory: 3932kb
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: 816ms
memory: 19820kb
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: 1833ms
memory: 36008kb
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: -100
Time Limit Exceeded
input:
22 983532313 168907597 985120947 845727304 401817563 702073670 841923182 372888321 835052818 409509378 73797974 256997223 101497367 919762407 912878630 297947923 723342631 32114398 409524923 253958495 441987041 591475412