QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#630102 | #6397. Master of Both III | Martian148 | WA | 0ms | 36348kb | C++20 | 929b | 2024-10-11 16:29:58 | 2024-10-11 16:30:05 |
Judging History
answer
#include <bits/stdc++.h>
using llsi = long long signed int;
int n;
inline llsi shift(llsi s, int y) {
s |= s << y | s >> (n - y);
s &= (1 << n) - 1;
return s;
}
llsi a[22];
llsi dp[1 << 22];
inline void chkmn(llsi &a, const llsi &b) {
if(b < a) a = b;
}
int main () {
std::ios::sync_with_stdio(false);
std::cin >> n;
for(int i = 0; i < n; ++i) std::cin >> a[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) {
chkmn(dp[shift(sta, n - j)], dp[sta] + a[j]);
}
// std::cout << "dp[" << i << "] = " << dp[i] << char(10);
}
for(int i = 1; i < (1 << n); ++i) {
// std::cout << "dp[" << i << "] = " << dp[i] << char(10);
}
llsi ans = 0;
constexpr llsi mod = 998244353;
for(int i = 1; i < (1 << n); ++i) ans = (ans + dp[i] * i) % mod;
std::cout << ans << char(10);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 36348kb
input:
3 2 1 2
output:
828691675
result:
wrong answer 1st numbers differ - expected: '45', found: '828691675'