QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#370933 | #6397. Master of Both III | ricofx# | WA | 1ms | 3680kb | C++17 | 1.8kb | 2024-03-29 19:44:26 | 2024-03-29 19:44:27 |
Judging History
answer
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define fi first
#define se second
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
//std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 998244353;
const int N = 4e6 + 5;
const ll inf = 1e15;
void add(int &x, int y) {
((x += y) >= mod) && (x -= mod);
}
int n;
ll w[25], dis[25][25], dp[(1 << 22) + 5];
void MAIN() {
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) dis[i][j] = inf;
}
for (int i = 0; i < n; i++) cin >> w[i];
for (int i = 0; i < n; i++) {
dis[i][i] = 0;
for (int j = 0; j < n; j++) dis[i][(i + j) % n] = min(dis[i][(i + j) % n], w[j]);
}
for (int k = 0; k < n; k++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
}
}
// cerr << dis[1][2] << '\n';
int mask = ((1 << n) - 1);
for (int i = 0; i <= mask; i++) dp[i] = inf;
dp[0] = 0;
for (int s = 0; s <= mask; s++) {
// cout << s << ' ' << dp[s] << '\n';
for (int j = 0; j < n; j++) if (j == 0 || ((s >> j) & 1)) {
for (int k = 0; k < n; k++) dp[s | (1 << k)] = min(dp[s | (1 << k)], dp[s] + dis[k][j]);
}
}
for (int s = mask; s >= 0; s--) {
for (int k = 0; k < n; k++) if (!(s >> k) & 1) dp[s] = min(dp[s], dp[s | (1 << k)]);
}
ll ans = 0;
for (int i = 1; i <= mask; i++) ans = (ans + dp[i] * (ll)i % mod) % mod;
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int T = 1;
//cin >> T;
while (T--) MAIN();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3664kb
input:
3 2 1 2
output:
45
result:
ok 1 number(s): "45"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
4 1919810 999999998 999999997 114114514
output:
152175989
result:
ok 1 number(s): "152175989"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3620kb
input:
3 842160586 705327547 868243944
output:
78597628
result:
ok 1 number(s): "78597628"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
5 198327434 147392532 760837755 771109105 676721155
output:
751568230
result:
ok 1 number(s): "751568230"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3680kb
input:
10 831766351 33417723 223739726 80131988 348810263 415437931 119999060 799356097 512022962 23197703
output:
458771697
result:
wrong answer 1st numbers differ - expected: '308170104', found: '458771697'