結果

問題 No.2523 Trick Flower
ユーザー kotatsugamekotatsugame
提出日時 2023-10-27 22:44:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,238 bytes
コンパイル時間 1,501 ms
コンパイル使用メモリ 74,392 KB
実行使用メモリ 12,048 KB
最終ジャッジ日時 2023-10-27 22:44:59
合計ジャッジ時間 3,585 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,612 KB
testcase_01 AC 2 ms
5,612 KB
testcase_02 AC 2 ms
5,612 KB
testcase_03 AC 2 ms
5,612 KB
testcase_04 AC 2 ms
5,612 KB
testcase_05 AC 2 ms
5,612 KB
testcase_06 AC 2 ms
5,612 KB
testcase_07 AC 2 ms
5,620 KB
testcase_08 AC 3 ms
5,636 KB
testcase_09 AC 3 ms
5,632 KB
testcase_10 AC 3 ms
5,624 KB
testcase_11 AC 3 ms
5,624 KB
testcase_12 AC 2 ms
5,624 KB
testcase_13 AC 3 ms
5,632 KB
testcase_14 AC 3 ms
5,628 KB
testcase_15 AC 60 ms
6,712 KB
testcase_16 AC 55 ms
6,712 KB
testcase_17 WA -
testcase_18 AC 63 ms
12,048 KB
testcase_19 AC 85 ms
6,616 KB
testcase_20 AC 85 ms
6,616 KB
testcase_21 AC 88 ms
6,616 KB
testcase_22 AC 84 ms
6,616 KB
testcase_23 AC 87 ms
6,616 KB
testcase_24 AC 47 ms
6,248 KB
testcase_25 AC 74 ms
6,536 KB
testcase_26 AC 72 ms
6,512 KB
testcase_27 AC 97 ms
6,584 KB
testcase_28 AC 67 ms
6,480 KB
testcase_29 AC 17 ms
5,904 KB
testcase_30 AC 56 ms
6,424 KB
testcase_31 AC 6 ms
5,720 KB
testcase_32 AC 33 ms
6,104 KB
testcase_33 AC 85 ms
6,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<cassert>
using namespace std;
int N,A[1<<17],B[1<<17],C[1<<17];
long need[1<<17];
int deg[1<<17];
bool vis[1<<17];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=0;i<N;i++)cin>>B[i];
	for(int i=0;i<N;i++)
	{
		cin>>C[i],C[i]--;
		deg[C[i]]++;
	}
	vector<int>Q;
	for(int i=0;i<N;i++)if(!deg[i])Q.push_back(i);
	for(int i=0;i<Q.size();i++)
	{
		int u=Q[i];
		vis[u]=true;
		if(!--deg[C[u]])Q.push_back(C[u]);
	}
	vector<vector<int> >Lp;
	for(int i=0;i<N;i++)if(!vis[i])
	{
		int u=i;
		Lp.push_back(vector<int>());
		while(!vis[u])
		{
			Lp.back().push_back(u);
			vis[u]=true;
			u=C[u];
		}
	}
	long L=0,R=1e15;
	while(R-L>1)
	{
		long k=(L+R)/2;
		bool out=false;
		for(int i=0;i<N;i++)
		{
			if(k&&B[i]&&B[i]>(long)1e15/k)
			{
				out=true;
				break;
			}
			need[i]=k*B[i];
		}
		if(out)
		{
			R=k;
			continue;
		}
		for(int u:Q)
		{
			need[C[u]]+=max(need[u]-A[u],0L);
		}
		for(int i=0;i<Lp.size();i++)
		{
			long sN=0,sA=0;
			for(int u:Lp[i])
			{
				sN+=need[u];
				sA+=A[u];
				if(sN>(long)1e15)break;
			}
			if(sN>sA)
			{
				out=true;
				break;
			}
		}
		if(out)R=k;
		else L=k;
	}
	cout<<L<<endl;
}
0