結果
| 問題 | 
                            No.2523 Trick Flower
                             | 
                    
| コンテスト | |
| ユーザー | 
                             沙耶花
                         | 
                    
| 提出日時 | 2023-10-27 23:12:26 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,254 bytes | 
| コンパイル時間 | 3,937 ms | 
| コンパイル使用メモリ | 257,024 KB | 
| 最終ジャッジ日時 | 2025-02-17 15:52:27 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 21 WA * 10 | 
ソースコード
#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]];
			//cout<<s[i][j]<<endl;
		}
	}
	rep(i,n){
		if(pos[i]==pos[c[i]])continue;
		E[pos[c[i]]].push_back(pos[i]);
	}
	/*
	rep(i,s.size()){
		rep(j,E[i].size()){
			cout<<E[i][j]<<' ';
		}
		cout<<endl;
	}
	*/
	long long ok = 0,ng = 200000000000000;
	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;
			rep(j,E[i].size()){
				ta[E[i][j]] += ta[i];
			}
			
		}
		if(f)ok = mid;
		else ng = mid;
	}
	cout<<ok<<endl;
	return 0;
}
            
            
            
        
            
沙耶花