結果

問題 No.2523 Trick Flower
ユーザー 沙耶花沙耶花
提出日時 2023-10-27 23:20:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 376 ms / 4,000 ms
コード長 1,222 bytes
コンパイル時間 4,935 ms
コンパイル使用メモリ 268,044 KB
実行使用メモリ 35,120 KB
最終ジャッジ日時 2023-10-27 23:20:44
合計ジャッジ時間 10,729 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 309 ms
35,120 KB
testcase_16 AC 295 ms
29,368 KB
testcase_17 AC 283 ms
22,184 KB
testcase_18 AC 225 ms
19,420 KB
testcase_19 AC 298 ms
22,220 KB
testcase_20 AC 285 ms
22,184 KB
testcase_21 AC 376 ms
22,228 KB
testcase_22 AC 252 ms
22,184 KB
testcase_23 AC 285 ms
22,184 KB
testcase_24 AC 157 ms
14,292 KB
testcase_25 AC 246 ms
20,232 KB
testcase_26 AC 225 ms
19,520 KB
testcase_27 AC 322 ms
21,292 KB
testcase_28 AC 224 ms
18,212 KB
testcase_29 AC 41 ms
7,024 KB
testcase_30 AC 187 ms
16,396 KB
testcase_31 AC 9 ms
4,580 KB
testcase_32 AC 105 ms
11,088 KB
testcase_33 AC 300 ms
21,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001


int main(){
	int n;
	cin>>n;
	vector<long long> a(n),b(n);
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>b[i];
	vector<int> c(n);
	scc_graph S(n);
	rep(i,n){
		cin>>c[i];
		c[i]--;
		S.add_edge(c[i],i);
	}
	auto s = S.scc();
	vector<int> pos(n);
	vector<long long> aa(s.size()),bb(s.size());
	vector<vector<int>> E(s.size());
	rep(i,s.size()){
		rep(j,s[i].size()){
			pos[s[i][j]] = i;
			aa[i] += a[s[i][j]];
			bb[i] += b[s[i][j]];
		}
	}
	rep(i,n){
		if(pos[i]==pos[c[i]])continue;
		E[pos[i]].push_back(pos[c[i]]);
	}

	long long ok = 0,ng = 2000000000000000;
	while(ng-ok>1LL){
		long long mid  =(ok+ng)/2;
		bool f = true;
		auto ta = aa,tb = bb;
		vector<__int128> need(s.size());
		for(int i=s.size()-1;i>=0;i--){
			__int128 t = bb[i];
			t *= mid;
			need[i] += t;
			if(ta[i]>=need[i]){
				continue;
			}
			if(E[i].size()==0){
				f = false;
				break;
			}
			need[E[i][0]] += need[i] - ta[i];
			
		}
		if(f)ok = mid;
		else ng = mid;
	}
	cout<<ok<<endl;
	return 0;
}
0