結果
問題 | No.1247 ブロック登り |
ユーザー | risujiroh |
提出日時 | 2020-10-03 20:18:34 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 467 ms / 3,000 ms |
コード長 | 3,035 bytes |
コンパイル時間 | 4,841 ms |
コンパイル使用メモリ | 377,776 KB |
実行使用メモリ | 112,956 KB |
最終ジャッジ日時 | 2023-09-25 06:43:30 |
合計ジャッジ時間 | 11,937 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 1 ms
4,380 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 1 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 4 ms
4,376 KB |
testcase_08 | AC | 4 ms
4,380 KB |
testcase_09 | AC | 2 ms
4,380 KB |
testcase_10 | AC | 3 ms
4,380 KB |
testcase_11 | AC | 466 ms
112,888 KB |
testcase_12 | AC | 430 ms
107,604 KB |
testcase_13 | AC | 458 ms
112,860 KB |
testcase_14 | AC | 465 ms
112,868 KB |
testcase_15 | AC | 455 ms
112,788 KB |
testcase_16 | AC | 462 ms
112,956 KB |
testcase_17 | AC | 463 ms
112,764 KB |
testcase_18 | AC | 397 ms
102,528 KB |
testcase_19 | AC | 36 ms
20,260 KB |
testcase_20 | AC | 13 ms
9,912 KB |
testcase_21 | AC | 3 ms
4,376 KB |
testcase_22 | AC | 8 ms
5,356 KB |
testcase_23 | AC | 7 ms
4,652 KB |
testcase_24 | AC | 2 ms
4,380 KB |
testcase_25 | AC | 456 ms
112,792 KB |
testcase_26 | AC | 467 ms
112,852 KB |
testcase_27 | AC | 465 ms
112,800 KB |
testcase_28 | AC | 462 ms
112,880 KB |
ソースコード
// #pragma GCC optimize("Ofast") // #pragma GCC target("avx2,bmi,bmi2,lzcnt") // #define NDEBUG #include <bits/extc++.h> #include <x86intrin.h> struct rep { struct iter { int i; constexpr void operator++() { ++i; } constexpr int operator*() const { return i; } friend constexpr bool operator!=(iter a, iter b) { return *a != *b; } }; const int l, r; constexpr rep(int _l, int _r) : l(std::min(_l, _r)), r(_r) {} constexpr rep(int n) : rep(0, n) {} constexpr iter begin() const { return {l}; } constexpr iter end() const { return {r}; } }; struct per { struct iter { int i; constexpr void operator++() { --i; } constexpr int operator*() const { return i; } friend constexpr bool operator!=(iter a, iter b) { return *a != *b; } }; const int l, r; constexpr per(int _l, int _r) : l(std::min(_l, _r)), r(_r) {} constexpr per(int n) : per(0, n) {} constexpr iter begin() const { return {r - 1}; } constexpr iter end() const { return {l - 1}; } }; template <class T, class U> constexpr bool chmin(T& a, U&& b) { return b < a ? a = std::forward<U>(b), true : false; } template <class T, class U> constexpr bool chmax(T& a, U&& b) { return a < b ? a = std::forward<U>(b), true : false; } int main() { using namespace std; cin.tie(nullptr)->sync_with_stdio(false); constexpr int inf = 0x3f3f3f3f; int n, k; cin >> n >> k; vector<int> a(n); for (auto&& e : a) cin >> e; vector dp(k + 1, vector(n, vector(n, -inf))); for (int i : rep(n)) dp[k][i][i] = a[i] * k; for (int v : per(1, k + 1)) for (int i : rep(n)) for (int j : rep(n)) { if (dp[v][i][j] == -inf) continue; if (i < j) { if (i) { int nv = v - 1; chmax(dp[nv][i - 1][j], dp[v][i][j] + a[i - 1] * nv); } if (j + 1 < n) { int nv = v - abs((j + 1) - i); if (nv >= 0) chmax(dp[nv][j + 1][i], dp[v][i][j] + a[j + 1] * nv); } if (v >= 2) chmax(dp[v - 2][i][j], dp[v][i][j]); } else if (j < i) { if (i + 1 < n) { int nv = v - 1; chmax(dp[nv][i + 1][j], dp[v][i][j] + a[i + 1] * nv); } if (j) { int nv = v - abs((j - 1) - i); if (nv >= 0) chmax(dp[nv][j - 1][i], dp[v][i][j] + a[j - 1] * nv); } if (v >= 2) chmax(dp[v - 2][i][j], dp[v][i][j]); } else { assert(i == j); assert(v == k); if (i) chmax(dp[v - 1][i - 1][j], dp[v][i][j] + a[i - 1] * (v - 1)); if (i + 1 < n) chmax(dp[v - 1][i + 1][j], dp[v][i][j] + a[i + 1] * (v - 1)); } } vector ans(n, -inf); for (int v : rep(k + 1)) for (int i : rep(n)) for (int j : rep(n)) { if (i + v <= j) chmax(ans[i + v], dp[v][i][j]); if (i - v >= j) chmax(ans[i - v], dp[v][i][j]); } for (int e : ans) cout << e << '\n'; }