結果

問題 No.2523 Trick Flower
ユーザー MasKoaTSMasKoaTS
提出日時 2023-03-31 18:11:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,446 bytes
コンパイル時間 2,257 ms
コンパイル使用メモリ 214,748 KB
実行使用メモリ 21,800 KB
最終ジャッジ日時 2023-10-25 21:07:33
合計ジャッジ時間 6,200 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,348 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,348 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,348 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 513 ms
21,800 KB
testcase_16 AC 488 ms
21,800 KB
testcase_17 AC 122 ms
8,292 KB
testcase_18 AC 110 ms
7,544 KB
testcase_19 AC 100 ms
9,656 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 101 ms
9,656 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 80 ms
8,864 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 18 ms
4,640 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 37 ms
5,960 KB
testcase_33 AC 87 ms
9,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/scc>
// WA(?)

#define all(x) x.begin(), x.end()
#define INF 1000000000000000000ll
using namespace std;
using namespace atcoder;
using ll = long long;


ll get_dp(ll mid, int n, vector<ll>& a, vector<ll>& b, vector<vector<int> >& route, vector<bool>& is_source, int x) {
	ll ret = a[x] - b[x] * mid;
	for (int k : route[x]) {
		ret += get_dp(mid, n, a, b, route, is_source, k);
	}
	if (ret > 0) {
		ret = 0;
	}
	return ret;
}


bool check(ll mid, int n, vector<ll>& a, vector<ll>& b, vector<vector<int> >& route, vector<bool>& is_source) {
	for (int i = 0; i < n; i++) {
		if (is_source[i] == false or get_dp(mid, n, a, b, route, is_source, i) >= 0) {
			continue;
		}
		return false;
	}
	return true;
}


int main(void){
	int n;	cin >> n;
	vector<ll> a(n), b(n);
	vector<int> c(n);
	ll sa = 0, sb = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];	sa += a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];	sb += b[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];	c[i]--;
	}

	vector<vector<int> > route(n, vector<int>({}));
	vector<bool> is_source(n, true);
	for (int i = 0; i < n; i++) {
		if (i == c[i]) {
			continue;
		}
		route[c[i]].push_back(i);
		is_source[i] = false;
	}

	ll ok = 0;
	ll ng = sa / sb + 1;
	while (ng - ok > 1) {
		ll mid = (ok + ng) >> 1ll;
		if (check(mid, n, a, b, route, is_source)) {
			ok = mid;
		}
		else {
			ng = mid;
		}
	}
	cout << ok << endl;

	return 0;
}
0