結果
問題 | No.484 収穫 |
ユーザー | Pachicobue |
提出日時 | 2018-11-21 02:59:46 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 158 ms / 3,000 ms |
コード長 | 1,039 bytes |
コンパイル時間 | 2,323 ms |
コンパイル使用メモリ | 198,256 KB |
最終ジャッジ日時 | 2025-01-06 17:02:43 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> using ll = long long; template <typename T> constexpr T INF = std::numeric_limits<T>::max() / 16; int main() { int N; std::cin >> N; std::vector<ll> A(N + 1); for (int i = 1; i <= N; i++) { std::cin >> A[i]; } std::vector<std::vector<ll>> l(N + 2, std::vector<ll>(N + 2, INF<ll>)), r(N + 2, std::vector<ll>(N + 2, INF<ll>)); l[2][N] = A[1], r[1][N - 1] = A[N]; for (int i = N - 2; i >= 0; i--) { for (int j = 1; j <= N - i; j++) { const int L = j, R = j + i; l[L + 1][R] = std::min(l[L + 1][R], std::max(l[L][R] + 1, A[L])); r[L][R - 1] = std::min(l[L][R - 1], std::max(l[L][R] + R - L + 1, A[R])); l[L + 1][R] = std::min(l[L + 1][R], std::max(r[L][R] + R - L + 1, A[L])); r[L][R - 1] = std::min(l[L][R - 1], std::max(r[L][R] + 1, A[R])); } } ll ans = INF<ll>; for (int i = 1; i <= N + 1; i++) { ans = std::min({ans, l[i][i - 1], r[i][i - 1]}); } std::cout << ans << std::endl; return 0; }