結果
問題 |
No.484 収穫
|
ユーザー |
![]() |
提出日時 | 2017-02-11 00:07:12 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,897 bytes |
コンパイル時間 | 1,886 ms |
コンパイル使用メモリ | 172,656 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-29 07:47:54 |
合計ジャッジ時間 | 2,594 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 9 WA * 12 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i, a, b) for (int i = (a); i < int(b); ++i) #define RFOR(i, a, b) for (int i = (b) - 1; i >= int(a); --i) #define rep(i, n) FOR(i, 0, n) #define rep1(i, n) FOR(i, 1, int(n) + 1) #define rrep(i, n) RFOR(i, 0, n) #define rrep1(i, n) RFOR(i, 1, int(n) + 1) #define all(c) begin(c), end(c) template<typename T> void __dump__(const T &first){ std::cerr << first << std::endl; } template<typename First, typename... Rest> void __dump__(const First& first, const Rest&... rest) { std::cerr << first << ", "; __dump__(rest...); } #define dump(...) { std::cerr << __LINE__ << ":\t" #__VA_ARGS__ " = "; __dump__(__VA_ARGS__); } #define int ll int n; vector<int> a; const int INF = 1e18; int opt[20][1<<20]; int dp(){ rep(i, 20) rep(j, 1 << 20) opt[i][j] = INF; rep(i, 20) opt[i][1<<i] = a[i]; rep(S, 1<<n) { rep(j, n) if(S >> j & 1){ rep(k, n) if(~S >> k & 1){ opt[k][S|1<<k] = min(opt[k][S|1<<k], max(opt[j][S] + abs(k - j), a[k])); } } } int ans = INF; rep(i, n) ans = min(ans, opt[i][(1<<n) - 1]); return ans; } int greedy(){ int ans = INF; rep(_, 2){ FOR(i, 1, n){ int time = a[0]; int j = 1; while(j < i){ time = max(time + 1, a[j]); ++j; } j = n - 1; time = max(time + (n - 1) - j, a[j]); while(j >= i){ time = max(time + 1, a[j]); --j; } ans = min(ans, time); } reverse(all(a)); } return ans; } signed main(){ while(cin >> n){ a.resize(n); rep(i, n) cin >> a[i]; // if(n < 20){ // cout << dp() << endl; // } else { cout << greedy() << endl; // } } }