結果
問題 | No.1247 ブロック登り |
ユーザー | 👑 hitonanode |
提出日時 | 2020-10-03 13:49:21 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 264 ms / 3,000 ms |
コード長 | 2,003 bytes |
コンパイル時間 | 1,070 ms |
コンパイル使用メモリ | 84,152 KB |
実行使用メモリ | 215,300 KB |
最終ジャッジ日時 | 2023-09-25 05:11:09 |
合計ジャッジ時間 | 5,496 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
7,696 KB |
testcase_01 | AC | 2 ms
9,820 KB |
testcase_02 | AC | 4 ms
11,636 KB |
testcase_03 | AC | 3 ms
7,516 KB |
testcase_04 | AC | 3 ms
11,736 KB |
testcase_05 | AC | 3 ms
13,712 KB |
testcase_06 | AC | 2 ms
5,432 KB |
testcase_07 | AC | 10 ms
40,928 KB |
testcase_08 | AC | 11 ms
42,832 KB |
testcase_09 | AC | 9 ms
36,256 KB |
testcase_10 | AC | 8 ms
30,348 KB |
testcase_11 | AC | 246 ms
215,300 KB |
testcase_12 | AC | 231 ms
206,148 KB |
testcase_13 | AC | 259 ms
215,012 KB |
testcase_14 | AC | 264 ms
215,000 KB |
testcase_15 | AC | 246 ms
215,004 KB |
testcase_16 | AC | 240 ms
215,004 KB |
testcase_17 | AC | 240 ms
215,128 KB |
testcase_18 | AC | 221 ms
204,352 KB |
testcase_19 | AC | 28 ms
39,172 KB |
testcase_20 | AC | 10 ms
17,988 KB |
testcase_21 | AC | 3 ms
6,412 KB |
testcase_22 | AC | 38 ms
115,780 KB |
testcase_23 | AC | 34 ms
113,708 KB |
testcase_24 | AC | 22 ms
101,380 KB |
testcase_25 | AC | 236 ms
215,020 KB |
testcase_26 | AC | 240 ms
215,076 KB |
testcase_27 | AC | 242 ms
215,128 KB |
testcase_28 | AC | 239 ms
215,008 KB |
ソースコード
#pragma GCC optimize("O3") #pragma GCC target("avx") #include <iostream> #include <vector> using namespace std; #define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) template <typename T> bool chmax(T& m, const T q) { return m < q ? (m = q, true) : false; } int main() { cin.tie(nullptr), ios::sync_with_stdio(false); int N, K; cin >> N >> K; vector<int> A(N); for (auto &x : A) cin >> x; constexpr int INF = 2e9; // vector dpl(K + 1, vector(N, vector(N, -INF))); // vector dpr(K + 1, vector(N, vector(N, -INF))); int dpl[301][300][300]; int dpr[301][300][300]; // array<array<array<int, 300>, 300>, 301> dpl; // array<array<array<int, 300>, 300>, 301> dpr; REP(k, K + 1) REP(i, N) REP(j, N) dpl[k][i][j] = dpr[k][i][j] = -INF; REP(i, N) dpl[K][i][i] = dpr[K][i][i] = A[i] * K; IFOR(k, 1, K + 1) { REP(l, N) FOR(r, l, N) { if (l < r and k > 1) { chmax(dpl[k - 2][l][r], dpl[k][l][r]); chmax(dpr[k - 2][l][r], dpr[k][l][r]); } if (l) chmax(dpl[k - 1][l - 1][r], dpl[k][l][r] + A[l - 1] * (k - 1)); if (r + 1 < N) chmax(dpr[k - 1][l][r + 1], dpr[k][l][r] + A[r + 1] * (k - 1)); if (k - (r - l) >= 0) chmax(dpr[k - (r - l)][l][r], dpl[k][l][r]); if (k - (r - l) >= 0) chmax(dpl[k - (r - l)][l][r], dpr[k][l][r]); } } IFOR(k, 1, K + 1) { REP(l, N) FOR(r, l + 1, N) { chmax(dpl[k - 1][l + 1][r], dpl[k][l][r]); chmax(dpr[k - 1][l][r - 1], dpr[k][l][r]); } } REP(i, N) { int ret = -INF; REP(j, N) { if (j <= i) chmax(ret, dpr[0][j][i]); if (i <= j) chmax(ret, dpl[0][i][j]); } cout << ret << '\n'; } }