結果

問題 No.2523 Trick Flower
ユーザー KKT89KKT89
提出日時 2023-10-27 22:00:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,216 bytes
コンパイル時間 3,094 ms
コンパイル使用メモリ 225,736 KB
実行使用メモリ 10,112 KB
最終ジャッジ日時 2023-10-27 22:00:13
合計ジャッジ時間 5,600 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
4,348 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 37 ms
9,080 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 41 ms
8,900 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 9 ms
4,636 KB
testcase_30 WA -
testcase_31 AC 4 ms
4,348 KB
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> a(n), b(n), c(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    vector<vector<int>> g(n);
    vector<int> deg(n);
    for (int i = 0; i < n; ++i) {
        cin >> c[i]; c[i] -= 1;
        deg[c[i]] += 1;
    }

    vector<int> odr, cyc;
    queue<int> q;
    for (int i = 0; i < n; ++i) {
        if (deg[i] == 0) {
            q.push(i);
        }
    }
    while (q.size()) {
        int s = q.front(); q.pop();
        odr.push_back(s);
        for (int t : g[s]) {
            deg[t] -= 1;
            if (deg[t] == 0) {
                q.push(t);
            }
        }
    }

    auto check = [&](ll x) -> bool {
        auto cp = a;
        vector<bool> used(n);
        for (int i : odr) {
            used[i] = true;
            if (b[i] > 1e18/x) return false;
            ll need = b[i]*x;
            if (cp[i] >= need) continue;
            ll dif = need - cp[i];
            cp[c[i]] -= dif;
        }
        for (int i = 0; i < n; ++i) {
            if (used[i]) continue;
            ll sa = 0, sb = 0;
            int j = i;
            while (!used[j]) {
                used[j] = true;
                sa += cp[j]; sb += b[j];
                j = c[j];
            }
//            cout << x << " " << sa << " " << sb << endl;
            if (sa < 0) return false;
            if (sb == 0) continue;
            if (sa/sb < x) return false;
        }
        return true;
    };

    ll l = 0, r = 1e18;
    while (r-l > 1) {
        ll mid = (l+r)/2;
        if (check(mid)) {
            l = mid;
        }
        else {
            r = mid;
        }
    }
    cout << l << endl;
}
0