QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#104896#6394. Turn on the Lightckiseki#TL 0ms0kbC++201.5kb2023-05-12 12:51:032023-05-12 12:51:06

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-12 12:51:06]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-05-12 12:51:03]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
template <typename ...T>
void debug_(const char *s, T ...a) {
    cerr << "\e[1;32m(" << s << ") = (";
    int cnt = sizeof...(T);
    (..., (cerr << a << (--cnt ? ", " : ")\e[0m\n")));
}
template <typename I>
void orange_(const char *s, I L, I R) {
    cerr << "\e[1;32m[ " << s << " ] = [ ";
    for (int f = 0; L != R; ++L)
        cerr << (f++ ? ", " : "") << *L;
    cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif

#define all(v) begin(v),end(v)

const int mod = 998244353;

int main() {
    int n;
    cin >> n;
    vector<int> w(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> w[i];
    }

    vector<int64_t> dp(1 << n, 1e18);
    const int S = (1 << n) - 1;
    dp[1] = 0;

    for (int s = 1; s < (1 << n); s++) {
        for (int i = 1; i <= n; i++) {
            int ns = ((s << i) | (s >> (n - i))) & S;
            ns |= s;
            dp[ns] = min(dp[ns], dp[s] + w[i]);
        }
    }

    orange(all(dp));

    for (int i = 0; i < n; i++)
        for (int s = 0; s < (1 << n); s++)
            if (~s >> i & 1)
                dp[s] = min(dp[s], dp[s ^ (1 << i)]);

    orange(all(dp));

    int64_t ans = 0;
    for (int s = 0; s < (1 << n); s++) {
        ans += dp[s] % mod * s % mod;
        ans %= mod;
    }

    cout << ans << '\n';

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

3

output:


result: