結果

問題 No.1122 Plane Tickets
ユーザー mencottonmencotton
提出日時 2020-07-22 22:44:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,318 bytes
コンパイル時間 690 ms
コンパイル使用メモリ 74,652 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-05 02:47:04
合計ジャッジ時間 3,090 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,356 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 WA -
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 WA -
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 WA -
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 WA -
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

const ll INF = (1LL << 62) - 1;

bool solve(vector<ll> v, ll target) {
    for (auto &x:v)x -= target;

    int maxPos = 0;
    for (int i = 0; i < 5; i++) {
        if (v[maxPos] < v[i]) maxPos = i;
    }

    ll addCount = 0;
    if (v[maxPos] <= -2) {
        addCount += (-v[maxPos]) / 2 * 5;
        for (auto &x:v)x += addCount / 5 * 2;
    }

    ll left = 0;
    vector<ll> tmp = v;
    for (int i = 0; i < 5; i++) {
        int here = (maxPos + i) % 5;
        if (tmp[here] < 0) {
            ll add = -tmp[here];
            left += add, tmp[here] += add, tmp[(here + 1) % 5] += add;
        }
    }
    ll right = 0;
    tmp = v;
    for (int i = 0; i < 5; i++) {
        int here = (maxPos - i + 5) % 5;
        if (tmp[here] < 0) {
            ll add = -tmp[here];
            right += add, tmp[here] += add, tmp[(here - 1 + 5) % 5] += add;
        }
    }

    addCount += min(left, right);

    return addCount <= target;
}

int main() {
    vector<ll> v(5);
    for (int i = 0; i < 5; i++)cin >> v[i];

    ll ok = 0, ng = 1e16;
    while (ng - ok > 1) {
        ll mid = ok + (ng - ok) / 2;
        if (solve(v, mid))ok = mid;
        else ng = mid;
    }

    cout << ok << endl;
    return 0;
}
0