QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#710511#6397. Master of Both IIItassei903WA 0ms3612kbC++231.3kb2024-11-04 20:12:262024-11-04 20:12:26

Judging History

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

  • [2024-11-04 20:12:26]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3612kb
  • [2024-11-04 20:12:26]
  • 提交

answer


#include <bits/stdc++.h>
#include <bits/extc++.h> 
using namespace std;
#define sz(x) (int)(x).size()
#define rep(i, l, r) for (int i = l; i < (r); i++)
#define rrep(i, l, r) for(int i = (int)(r)-1; i >= (int)(l); i--)
#define all(x) begin(x), end(x)

using ll = long long;
using vi = vector<int>;

using pii = pair<int, int>;

const ll inf = 1e18;
const ll mod = 998244353;

int main() {
    std::cin.tie(0)->sync_with_stdio(0);

    int n;cin >> n;
    vector<ll> w(n);rep(i, 0, n) cin >> w[i];
    vector<ll> dp(1<<n, inf);
    dp[1] = 0;
    ll z = (1 << n) - 1;
    for(ll i = 0; i < 1<<n ; i++) {
        rep(j, 0, n) {
            ll x = (i | (i << j) | ((i << j) >> n)) & z;
            cout << i << " " << j << " " << x << endl;
            dp[x] = min(dp[x], dp[i] + w[j]);
        }
    }

    for(int i = (1<<n) - 1; i >= 1; i--) {
        rep(j, 0, n) {
            if (i >> j & 1) continue;
            dp[i] = min(dp[i], dp[i | (1 << j)]);
        }
    }

    ll ans = 0;
    rep(i, 1, 1<<n) {
        ll x = 0;
        rep(j, 0, n) {
            if (i >> j & 1) {
                if (j == 0) x += 1;
                else x += (1 << (n - j));
            }
        }
        ans += dp[i] * x % mod;
        ans %= mod;
        // cout << i << " " << dp[i] << endl;
    }
    cout << ans << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3612kb

input:

3
2 1 2

output:

0 0 0
0 1 0
0 2 0
1 0 1
1 1 3
1 2 5
2 0 2
2 1 6
2 2 3
3 0 3
3 1 7
3 2 7
4 0 4
4 1 5
4 2 6
5 0 5
5 1 7
5 2 7
6 0 6
6 1 7
6 2 7
7 0 7
7 1 7
7 2 7
45

result:

wrong answer 1st numbers differ - expected: '45', found: '0'