結果

問題 No.9 モンスターのレベル上げ
ユーザー Shuz*Shuz*
提出日時 2019-07-24 18:19:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 486 ms / 5,000 ms
コード長 4,222 bytes
コンパイル時間 1,809 ms
コンパイル使用メモリ 174,700 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 10:47:00
合計ジャッジ時間 7,294 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 486 ms
4,380 KB
testcase_03 AC 389 ms
4,376 KB
testcase_04 AC 203 ms
4,376 KB
testcase_05 AC 135 ms
4,380 KB
testcase_06 AC 45 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 61 ms
4,376 KB
testcase_09 AC 469 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 417 ms
4,376 KB
testcase_12 AC 342 ms
4,376 KB
testcase_13 AC 266 ms
4,376 KB
testcase_14 AC 471 ms
4,376 KB
testcase_15 AC 432 ms
4,376 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 276 ms
4,380 KB
testcase_18 AC 231 ms
4,376 KB
testcase_19 AC 5 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
const ll mod = 998244353;
const ll inf = 1 << 30;
const ll LINF = LONG_MAX;
const ll INF = 1LL << 60;
const ull MAX = ULONG_MAX;
#define mp make_pair
#define pb push_back
#define elif else if
#define endl '\n'
#define space ' '
#define def inline auto
#define func inline constexpr ll
#define run(a) __attribute__((constructor)) def _##a()
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
#define input(a) scanf("%lld", &(a))
#define print(a) printf("%lld\n", (a))
#define fi first
#define se second
#define ok(a, b) (0 <= (a) && (a) < (b))
template <class T> using vvector = vector<vector<T>>;
template <class T> using pvector = vector<pair<T, T>>;
template <class T>
using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;

template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

// Debug
#define debug(...)                                                             \
    {                                                                          \
        cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ";                     \
        for (auto &&X : {__VA_ARGS__}) cerr << "[" << X << "] ";               \
        cerr << endl;                                                          \
    }

#define dump(a, h, w)                                                          \
    {                                                                          \
        cerr << __LINE__ << ": " << #a << " = [" << endl;                      \
        rep(__i, h) {                                                          \
            rep(__j, w) cerr << a[__i][__j] << space;                          \
            cerr << endl;                                                      \
        }                                                                      \
        cerr << "]" << endl;                                                   \
    }

#define vdump(a, n)                                                            \
    {                                                                          \
        cerr << __LINE__ << ": " << #a << " = [";                              \
        rep(__i, n) if (__i) cerr << space << a[__i];                          \
        else cerr << a[__i];                                                   \
        cerr << "]" << endl;                                                   \
    }

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define rep(i, n) for (ll i = 0, _##i = (n); i < _##i; ++i)
#define each(i, a) for (auto &&i : a)
#define loop() for (;;)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)
run(0) { fasten, fout(10); }

// Speed
#pragma GCC optimize("O3")
#pragma GCC target("avx")

// Math
func gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
func lcm(ll a, ll b) { return a * b / gcd(a, b); }
func sign(ll a) { return a ? abs(a) / a : 0; }

inline constexpr ll modulo(const ll n, const ll m) noexcept {
    if (n < 0) {
        return n % m + m;
    } else if (n >= m) {
        return n % m;
    } else {
        return n;
    }
}

signed main() {
    ll N, res = INF;
    cin >> N;
    const ull n = N;
    ll A[N], B[N];
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i], B[i] /= 2;
    rpriority_queue<pair<ll, ll>> P;
    rep(i, N) {
        rep(i, N) P.push({A[i], 0});
        rep(j, N) {
            ll id = modulo(i + j, N), lv, n;
            tie(lv, n) = P.top(), P.pop();
            P.push({lv + B[id], n + 1});
        }
        ll max = 0;
        while (P.size()) {
            ll lv, n;
            tie(lv, n) = P.top(), P.pop();
            chmax(max, n);
        }
        chmin(res, max);
    }
    cout << res << endl;
}
0