結果

問題 No.2523 Trick Flower
ユーザー 沙耶花沙耶花
提出日時 2023-10-27 23:16:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,186 bytes
コンパイル時間 4,697 ms
コンパイル使用メモリ 266,568 KB
実行使用メモリ 33,532 KB
最終ジャッジ日時 2023-10-27 23:16:49
合計ジャッジ時間 7,625 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 2 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 AC 209 ms
33,532 KB
testcase_16 AC 165 ms
27,780 KB
testcase_17 AC 156 ms
18,484 KB
testcase_18 AC 145 ms
17,832 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 117 ms
17,764 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 23 ms
6,540 KB
testcase_30 WA -
testcase_31 AC 6 ms
4,476 KB
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

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[c[i]]].push_back(pos[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;
		rep(i,s.size()){
			__int128 t = bb[i];
			t *= mid;
			if(t>ta[i]){
				f = false;
				break;
			}
			ta[i] -= t;
			//assert(E[i].size()<=1);
			rep(j,E[i].size()){
				if(j==1)break;
				ta[E[i][j]] += ta[i];
			}
			
		}
		if(f)ok = mid;
		else ng = mid;
	}
	cout<<ok<<endl;
	return 0;
}
0