結果

問題 No.484 収穫
ユーザー tubo28tubo28
提出日時 2017-02-10 23:43:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,841 bytes
コンパイル時間 1,564 ms
コンパイル使用メモリ 168,384 KB
実行使用メモリ 167,404 KB
最終ジャッジ日時 2023-08-28 10:18:18
合計ジャッジ時間 4,612 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
167,208 KB
testcase_01 AC 46 ms
167,184 KB
testcase_02 AC 45 ms
167,180 KB
testcase_03 AC 46 ms
167,204 KB
testcase_04 AC 46 ms
167,260 KB
testcase_05 AC 46 ms
167,404 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 133 ms
4,376 KB
testcase_13 AC 133 ms
4,376 KB
testcase_14 AC 133 ms
4,376 KB
testcase_15 AC 134 ms
4,380 KB
testcase_16 AC 133 ms
4,376 KB
testcase_17 AC 133 ms
4,380 KB
testcase_18 AC 133 ms
4,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 133 ms
4,376 KB
testcase_23 AC 133 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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(){ // muri
    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){
        rep(i, n){
            // dump(i);
            int pos = i;
            int time = a[pos];
            rep(j, n - 1){
                int npos = (pos + 1) % n;
                time = max(time + abs(pos - npos), a[npos]);
                pos = npos;
                // dump(time);
            }
            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;
        }
    }
}
0