結果
問題 | No.1365 [Cherry 1st Tune] Whose Fault? |
ユーザー | 👑 jupiro |
提出日時 | 2021-01-23 00:21:08 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 361 ms / 2,000 ms |
コード長 | 2,902 bytes |
コンパイル時間 | 2,226 ms |
コンパイル使用メモリ | 139,680 KB |
実行使用メモリ | 8,040 KB |
最終ジャッジ日時 | 2023-08-28 11:57:29 |
合計ジャッジ時間 | 22,164 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 2 ms
4,376 KB |
testcase_08 | AC | 2 ms
4,380 KB |
testcase_09 | AC | 1 ms
4,376 KB |
testcase_10 | AC | 2 ms
4,376 KB |
testcase_11 | AC | 2 ms
4,376 KB |
testcase_12 | AC | 2 ms
4,376 KB |
testcase_13 | AC | 32 ms
4,380 KB |
testcase_14 | AC | 22 ms
4,380 KB |
testcase_15 | AC | 6 ms
4,380 KB |
testcase_16 | AC | 5 ms
4,376 KB |
testcase_17 | AC | 19 ms
4,376 KB |
testcase_18 | AC | 11 ms
4,376 KB |
testcase_19 | AC | 31 ms
4,380 KB |
testcase_20 | AC | 19 ms
4,380 KB |
testcase_21 | AC | 28 ms
4,380 KB |
testcase_22 | AC | 23 ms
4,376 KB |
testcase_23 | AC | 68 ms
5,444 KB |
testcase_24 | AC | 146 ms
6,144 KB |
testcase_25 | AC | 287 ms
6,404 KB |
testcase_26 | AC | 200 ms
6,028 KB |
testcase_27 | AC | 236 ms
4,600 KB |
testcase_28 | AC | 100 ms
4,380 KB |
testcase_29 | AC | 82 ms
4,632 KB |
testcase_30 | AC | 361 ms
6,840 KB |
testcase_31 | AC | 320 ms
7,480 KB |
testcase_32 | AC | 181 ms
7,036 KB |
testcase_33 | AC | 281 ms
5,416 KB |
testcase_34 | AC | 221 ms
5,252 KB |
testcase_35 | AC | 133 ms
6,612 KB |
testcase_36 | AC | 266 ms
7,540 KB |
testcase_37 | AC | 56 ms
4,380 KB |
testcase_38 | AC | 73 ms
6,496 KB |
testcase_39 | AC | 332 ms
6,220 KB |
testcase_40 | AC | 330 ms
6,288 KB |
testcase_41 | AC | 253 ms
6,812 KB |
testcase_42 | AC | 232 ms
4,504 KB |
testcase_43 | AC | 1 ms
4,380 KB |
testcase_44 | AC | 101 ms
8,040 KB |
testcase_45 | AC | 134 ms
4,380 KB |
ソースコード
#include <iostream> #include <string> #include <sstream> #include <stack> #include <algorithm> #include <cmath> #include <queue> #include <bitset> #include <iomanip> #include <limits> #include <chrono> #include <random> #include <array> #include <unordered_map> #include <functional> #include <complex> #include <numeric> #include <cctype> #include <map> #include <set> #include <cstdlib> #include <bitset> #include <tuple> #include <assert.h> #include <deque> #include <utility> #include <fstream> using namespace std; typedef long long ll; using ull = unsigned long long; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } //template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); }return a; } //mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); constexpr long long INF = 1LL << 60; constexpr int inf = 1000000007; constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353; class UnionFind { public: vector<int> Parent; UnionFind(int N) { Parent = vector<int>(N, -1); } int root(int A) { if (Parent[A] < 0) { return A; } return Parent[A] = root(Parent[A]); } long long size(int A) { return -(long long)Parent[root(A)]; } bool connect(int A, int B) { A = root(A); B = root(B); if (A == B) { return false; } if (size(A) < size(B)) { swap(A, B); } Parent[A] += Parent[B]; Parent[B] = A; return true; } bool same(int A, int B) { return root(A) == root(B); } }; int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); using Real = double; int n; cin >> n; vector<ll> a(n); for (auto& e : a) cin >> e; vector<ll> b(n); for (auto& e : b) cin >> e; vector<ll> p(n); for (auto& e : p) cin >> e; UnionFind uf(n); vector<Real> res(n); vector<Real> rp(n); vector<ll> pn(n); auto f = [&](Real x, Real y) {return (x - y) * (x - y); }; for (int i = 0; i < n; i++) res[i] = (double)p[i] * f(a[i], b[i]), rp[i] = 1.0 / (Real)p[i], pn[i] += a[i] - b[i]; int kkt; cin >> kkt; Real pre = 0; for (int i = 0; i < n; i++) pre += res[i]; while (kkt--) { int u, v; cin >> u >> v; u--; v--; u = uf.root(u); v = uf.root(v); if (uf.same(u, v)) { cout << fixed << setprecision(15) << pre << "\n"; } else { Real ans = pre - res[u] - res[v]; vector<ll> cn(101); Real p = abs(pn[u] + pn[v]); Real t = pn[u] + pn[v]; Real ch = 0; if (cn[0] > 0) { cout << fixed << setprecision(15) << ans << "\n"; pre = ans; } else { ch = p * p / (rp[u] + rp[v]); ans += ch; cout << fixed << setprecision(15) << ans << "\n"; pre = ans; } uf.connect(u, v); int root = uf.root(u); res[root] = ch; rp[root] = rp[u] + rp[v]; pn[root] = t; } } }