結果
問題 | No.1247 ブロック登り |
ユーザー | mkawa2 |
提出日時 | 2021-08-19 00:18:37 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 423 ms / 3,000 ms |
コード長 | 1,506 bytes |
コンパイル時間 | 1,922 ms |
コンパイル使用メモリ | 200,208 KB |
実行使用メモリ | 225,332 KB |
最終ジャッジ日時 | 2024-04-20 03:33:24 |
合計ジャッジ時間 | 9,564 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 93 ms
225,204 KB |
testcase_01 | AC | 110 ms
225,276 KB |
testcase_02 | AC | 90 ms
225,188 KB |
testcase_03 | AC | 73 ms
225,172 KB |
testcase_04 | AC | 75 ms
225,204 KB |
testcase_05 | AC | 79 ms
225,208 KB |
testcase_06 | AC | 74 ms
225,168 KB |
testcase_07 | AC | 72 ms
225,180 KB |
testcase_08 | AC | 76 ms
225,020 KB |
testcase_09 | AC | 81 ms
225,116 KB |
testcase_10 | AC | 102 ms
225,044 KB |
testcase_11 | AC | 378 ms
225,136 KB |
testcase_12 | AC | 351 ms
224,964 KB |
testcase_13 | AC | 423 ms
225,080 KB |
testcase_14 | AC | 375 ms
225,232 KB |
testcase_15 | AC | 411 ms
225,120 KB |
testcase_16 | AC | 373 ms
225,084 KB |
testcase_17 | AC | 400 ms
225,216 KB |
testcase_18 | AC | 350 ms
225,292 KB |
testcase_19 | AC | 97 ms
225,088 KB |
testcase_20 | AC | 81 ms
225,224 KB |
testcase_21 | AC | 76 ms
225,116 KB |
testcase_22 | AC | 115 ms
225,160 KB |
testcase_23 | AC | 76 ms
224,980 KB |
testcase_24 | AC | 96 ms
225,332 KB |
testcase_25 | AC | 358 ms
225,120 KB |
testcase_26 | AC | 401 ms
225,100 KB |
testcase_27 | AC | 367 ms
224,960 KB |
testcase_28 | AC | 379 ms
225,148 KB |
ソースコード
// #include <atcoder/all> // using namespace atcoder; #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define all(x) (x).begin(), (x).end() using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; using vvi = vector<vector<int>>; const int inf = 1e9; const ll lim = 1e18; int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}; int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; int dp[305][2][305][305]; void chmax(int &a, const int &b) { a = max(a, b); } int main() { cin.tie(0); ios::sync_with_stdio(false); rep(i, 305) rep(j, 2) rep(k, 305) rep(l, 305) dp[i][j][k][l] = -inf; int n, k, d; cin >> n >> k; vi a(n); rep(i, n) cin >> a[i]; rep(i, n) dp[k][0][i][i] = a[i] * k; vi ans(n, -inf); for (int i = k; i >= 0; i--) { rep(j, 2) { rep(l, n) { for (int r = l; r < n; r++) { int pre = dp[i][j][l][r]; if (pre == -inf) continue; int p = j ? r - i : l + i; if (l <= p && p <= r) chmax(ans[p], pre); if (i - 2 >= 0 && l != r) chmax(dp[i - 2][j][l][r], pre); d = j ? r - l + 1 : 1; if (l - 1 >= 0 && i - d >= 0) chmax(dp[i - d][0][l - 1][r], pre + a[l - 1] * (i - d)); d = j ? 1 : r - l + 1; if (r + 1 < n && i - d >= 0) chmax(dp[i - d][1][l][r + 1], pre + a[r + 1] * (i - d)); } } } } rep(i, n) cout << ans[i] << endl; return 0; }