結果

問題 No.1365 [Cherry 1st Tune] Whose Fault?
ユーザー vkgainzvkgainz
提出日時 2021-06-12 13:39:08
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,458 bytes
コンパイル時間 4,802 ms
コンパイル使用メモリ 131,616 KB
実行使用メモリ 53,916 KB
最終ジャッジ日時 2023-08-22 11:15:52
合計ジャッジ時間 19,894 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,784 KB
testcase_01 AC 2 ms
6,032 KB
testcase_02 AC 3 ms
6,032 KB
testcase_03 AC 3 ms
6,048 KB
testcase_04 AC 3 ms
5,948 KB
testcase_05 AC 3 ms
6,228 KB
testcase_06 AC 3 ms
6,072 KB
testcase_07 AC 3 ms
6,172 KB
testcase_08 AC 3 ms
6,056 KB
testcase_09 AC 2 ms
5,960 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 342 ms
53,916 KB
testcase_45 AC 450 ms
6,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int par[100001], sz[100001];
int freq[100001][11][11];
long long X[100001];
double val[100001];
double ans;

int find(int x) {
    if(x == par[x]) return x;
    return par[x] = find(par[x]);
}

void merge(int x, int y) {
    if(find(x) == find(y)) return;
    x = find(x), y = find(y);
    if(sz[x] < sz[y]) swap(x, y);
    X[x] += X[y];
    par[y] = x;
    sz[x] += sz[y];
    ans -= val[x];
    ans -= val[y];
    double num = X[x], den = 0.0;
    for(int i = 0; i <= 10; i++) {
        for(int j = 0; j <= 10; j++) {
            freq[x][i][j] += freq[y][i][j];
            num -= freq[x][i][j] * j;
            if(i)
                den += freq[x][i][j] * 1.0 / i;
        }
    }
    ans += num * 1.0 * num / den;
    val[x] = num * 1.0 * num / den;
}

int main() {
    int N; cin >> N;
    vector<int> A(N), B(N), P(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 >> P[i];
    }
    iota(par, par + N, 0);
    memset(sz, 1, sizeof(sz));
    for(int i = 0; i < N; i++) {
        X[i] = A[i];
        val[i] = P[i] * (A[i] - B[i]) * (A[i] - B[i]);
        freq[i][P[i]][B[i]] = 1;
        ans += val[i];
    }
    cout << setprecision(24);
    int Q; cin >> Q;
    while(Q--) {
        int X, Y; cin >> X >> Y;
        --X, --Y;
        merge(X, Y);
        cout << ans << "\n";
    }
}
0