QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#630191 | #6397. Master of Both III | Martian148 | RE | 0ms | 3580kb | C++20 | 1.2kb | 2024-10-11 16:57:56 | 2024-10-11 16:57:57 |
Judging History
answer
#include <bits/stdc++.h>
using llsi = long long signed int;
constexpr int N = 3;
constexpr llsi MOD = 998244353;
int n;
inline llsi shift (llsi s, int y) {
s |= s << y | s >> (n - y);
s &= (1 << n) - 1;
return s;
}
llsi w[N];
llsi dp[1 << N];
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0); std::cout.tie(0);
std::cin >> n;
for (int i = 0; i < n; i++) std::cin >> w[i];
memset(dp, 0x3f, sizeof dp);
dp[1] = 0;
for (int i = 1; i < (1 << n); i++) {
llsi sta = i;
for (int j = 1; j < n; j++) {
llsi nxt = shift(sta, n - j);
dp[nxt] = std::min(dp[nxt], dp[sta] + w[j]);
}
}
for (int i = (1 << n) - 1; ~i; i--) {
llsi sta = i;
for (int j = 0; j < n; j++)
if (!(sta >> j & 1)) {
llsi nxt = sta | 1 << j;
dp[sta] = std::min(dp[nxt], dp[sta]);
}
}
// for (int i = 1; i < (1 << n); i++) {
// std::cout << "dp[" << i << "] = " << dp[i] << std::endl;
// }
llsi ans = 0;
for (int i = 1; i < (1 << n); i++) ans = (ans + dp[i] * i) % MOD;
std::cout << ans << std::endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
input:
3 2 1 2
output:
45
result:
ok 1 number(s): "45"
Test #2:
score: -100
Runtime Error
input:
4 1919810 999999998 999999997 114114514