結果
| 問題 |
No.2523 Trick Flower
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-10-27 22:08:21 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,291 bytes |
| コンパイル時間 | 2,601 ms |
| コンパイル使用メモリ | 225,284 KB |
| 最終ジャッジ日時 | 2025-02-17 15:06:32 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 WA * 1 |
ソースコード
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
inline double time() {
return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n; cin >> n;
vector<ll> a(n), b(n), c(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < n; ++i) {
cin >> b[i];
}
vector<vector<int>> g(n);
vector<int> deg(n);
for (int i = 0; i < n; ++i) {
cin >> c[i]; c[i] -= 1;
deg[c[i]] += 1;
g[i].push_back(c[i]);
}
vector<int> odr, cyc;
queue<int> q;
for (int i = 0; i < n; ++i) {
if (deg[i] == 0) {
q.push(i);
}
}
while (q.size()) {
int s = q.front(); q.pop();
odr.push_back(s);
for (int t : g[s]) {
deg[t] -= 1;
if (deg[t] == 0) {
q.push(t);
}
}
}
auto check = [&](ll x) -> bool {
auto cp = a;
vector<bool> used(n);
for (int i : odr) {
used[i] = true;
if (b[i] > 1e17/x) return false;
if (cp[i] < -1e18) return false;
ll need = b[i]*x;
if (cp[i] >= need) continue;
ll dif = need - cp[i];
cp[c[i]] -= dif;
}
for (int i = 0; i < n; ++i) {
if (used[i]) continue;
ll sa = 0, sb = 0;
int j = i;
while (!used[j]) {
used[j] = true;
sa += cp[j]; sb += b[j];
j = c[j];
}
// cout << x << " " << sa << " " << sb << endl;
if (sa < 0) return false;
if (sb == 0) continue;
if (sa/sb < x) return false;
}
return true;
};
ll l = 0, r = 1e18;
while (r-l > 1) {
ll mid = (l+r)/2;
if (check(mid)) {
l = mid;
}
else {
r = mid;
}
}
cout << l << endl;
}