QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#104896 | #6394. Turn on the Light | ckiseki# | TL | 0ms | 0kb | C++20 | 1.5kb | 2023-05-12 12:51:03 | 2023-05-12 12:51:06 |
Judging History
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