QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#630191#6397. Master of Both IIIMartian148RE 0ms3580kbC++201.2kb2024-10-11 16:57:562024-10-11 16:57:57

Judging History

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

  • [2024-10-11 16:57:57]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3580kb
  • [2024-10-11 16:57:56]
  • 提交

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;
}

詳細信息

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

output:


result: