結果
| 問題 |
No.2523 Trick Flower
|
| コンテスト | |
| ユーザー |
shobonvip
|
| 提出日時 | 2023-10-27 23:49:24 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,255 bytes |
| コンパイル時間 | 4,454 ms |
| コンパイル使用メモリ | 257,444 KB |
| 最終ジャッジ日時 | 2025-02-17 16:13:46 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 TLE * 1 -- * 18 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/
/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/
typedef long long ll;
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
template <typename T> bool chmin(T &a, const T &b) {
if (a <= b) return false;
a = b;
return true;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a >= b) return false;
a = b;
return true;
}
template <typename T> T max(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
return ret;
}
template <typename T> T min(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
return ret;
}
template <typename T> T sum(vector<T> &a){
T ret = 0;
for (int i=0; i<(int)a.size(); i++) ret += a[i];
return ret;
}
// defcomp
template <typename T>
vector<T> compress(vector<T> &X) {
vector<T> vals = X;
sort(vals.begin(), vals.end());
vals.erase(unique(vals.begin(), vals.end()), vals.end());
return vals;
}
// -----
// importbisect
template <typename T>
int bisect_left(vector<T> &X, T v){
return lower_bound(X.begin(), X.end(), v) - X.begin();
}
template <typename T>
int bisect_right(vector<T> &X, T v){
return upper_bound(X.begin(), X.end(), v) - X.begin();
}
// -----
int main(){
int n; cin >> n;
vector<ll> a(n), b(n);
vector<int> c(n);
rep(i,0,n) cin >> a[i];
rep(i,0,n) cin >> b[i];
rep(i,0,n){
cin >> c[i];
c[i]--;
}
ll inf = 2e18 + 5;
ll g = sum(b);
auto can = [&](ll t) -> bool {
mf_graph<ll> mf(n+2);
rep(i,0,n){
mf.add_edge(n, i, a[i]);
}
rep(i,0,n){
mf.add_edge(c[i], i, inf);
}
rep(i,0,n){
mf.add_edge(i, n+1, b[i]*t);
}
//cout << t << ' ' << mf.flow(2*n, 2*n+1) << ' ' << g*t << endl;
if (mf.flow(n, n+1) == g*t){
return true;
}else{
return false;
}
};
ll ub = sum(a) / g + 1;
ll lb = 0;
//cout << lb << ' ' << ub << endl;
while(ub - lb > 1){
ll t = (ub + lb) / 2;
if (can(t)){
lb = t;
}else{
ub = t;
}
}
cout << lb << '\n';
}
shobonvip