結果
問題 | No.1365 [Cherry 1st Tune] Whose Fault? |
ユーザー | moririn2528_c |
提出日時 | 2021-01-23 05:03:55 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 762 ms / 2,000 ms |
コード長 | 3,027 bytes |
コンパイル時間 | 1,720 ms |
コンパイル使用メモリ | 103,644 KB |
実行使用メモリ | 8,584 KB |
最終ジャッジ日時 | 2023-08-28 14:45:38 |
合計ジャッジ時間 | 31,252 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 1 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,380 KB |
testcase_08 | AC | 2 ms
4,376 KB |
testcase_09 | AC | 2 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,380 KB |
testcase_13 | AC | 67 ms
4,380 KB |
testcase_14 | AC | 46 ms
4,376 KB |
testcase_15 | AC | 13 ms
4,380 KB |
testcase_16 | AC | 11 ms
4,376 KB |
testcase_17 | AC | 38 ms
4,376 KB |
testcase_18 | AC | 23 ms
4,380 KB |
testcase_19 | AC | 66 ms
4,380 KB |
testcase_20 | AC | 53 ms
4,376 KB |
testcase_21 | AC | 59 ms
4,376 KB |
testcase_22 | AC | 50 ms
4,376 KB |
testcase_23 | AC | 149 ms
5,788 KB |
testcase_24 | AC | 312 ms
6,408 KB |
testcase_25 | AC | 611 ms
6,812 KB |
testcase_26 | AC | 422 ms
6,212 KB |
testcase_27 | AC | 492 ms
4,708 KB |
testcase_28 | AC | 245 ms
4,380 KB |
testcase_29 | AC | 176 ms
4,764 KB |
testcase_30 | AC | 762 ms
6,892 KB |
testcase_31 | AC | 670 ms
8,008 KB |
testcase_32 | AC | 380 ms
7,156 KB |
testcase_33 | AC | 620 ms
5,812 KB |
testcase_34 | AC | 485 ms
5,544 KB |
testcase_35 | AC | 278 ms
6,736 KB |
testcase_36 | AC | 557 ms
7,864 KB |
testcase_37 | AC | 120 ms
4,384 KB |
testcase_38 | AC | 164 ms
6,744 KB |
testcase_39 | AC | 716 ms
6,468 KB |
testcase_40 | AC | 707 ms
6,532 KB |
testcase_41 | AC | 533 ms
7,328 KB |
testcase_42 | AC | 506 ms
4,496 KB |
testcase_43 | AC | 2 ms
4,384 KB |
testcase_44 | AC | 312 ms
8,584 KB |
testcase_45 | AC | 430 ms
4,380 KB |
コンパイルメッセージ
次のファイルから読み込み: /usr/local/gcc7/include/c++/12.2.0/vector:64, 次から読み込み: main.cpp:5: メンバ関数 ‘void std::vector<_Tp, _Alloc>::assign(size_type, const value_type&) [with _Tp = node; _Alloc = std::allocator<node>]’ 内, inlined from ‘void union_find_tree::init()’ at main.cpp:70:18, inlined from ‘union_find_tree::union_find_tree(int)’ at main.cpp:75:13: /usr/local/gcc7/include/c++/12.2.0/bits/stl_vector.h:804:23: 警告: ‘<anonymous>’ may be used uninitialized [-Wmaybe-uninitialized] 804 | { _M_fill_assign(__n, __val); } | ~~~~~~~~~~~~~~^~~~~~~~~~~~ 次のファイルから読み込み: /usr/local/gcc7/include/c++/12.2.0/vector:70: /usr/local/gcc7/include/c++/12.2.0/bits/vector.tcc: コンストラクタ ‘union_find_tree::union_find_tree(int)’ 内: /usr/local/gcc7/include/c++/12.2.0/bits/vector.tcc:264:5: 備考: by argument 3 of type ‘const std::vector<node>::value_type&’ {aka ‘const node&’} to ‘void std::vector<_Tp, _Alloc>::_M_fill_assign(std::size_t, const value_type&) [with _Tp = node; _Alloc = std::allocator<node>]’ declared here 264 | vector<_Tp, _Alloc>:: | ^~~~~~~~~~~~~~~~~~~ main.cpp:70:26: 備考: ‘<anonymous>’ はここで宣言されています 70 | v1.assign(n,node()); | ^
ソースコード
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<vector> #include<cmath> #include<algorithm> #include<map> #include<queue> #include<deque> #include<iomanip> #include<tuple> #include<cassert> #include<set> #include<complex> #include<numeric> #include<functional> using namespace std; typedef long long int LL; typedef pair<int,int> P; typedef pair<LL,int> LP; const int INF=1<<30; const LL MAX=1e9+7; void array_show(int *array,int array_n,char middle=' '){ for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n')); } void array_show(LL *array,int array_n,char middle=' '){ for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n')); } void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){ if(vec_n==-1)vec_n=vec_s.size(); for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n')); } void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){ if(vec_n==-1)vec_n=vec_s.size(); for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n')); } typedef class node{ typedef long double D; public: D a,b,p; node(D _a,D _b,D _p):a(_a),b(_b),p(_p){} node(){} void connect(node n1){ b+=n1.b; a+=n1.a; if(p==0 || n1.p==0)p=0; else p=p*n1.p/(p+n1.p); } D calc(){ return p*powl(a-b,2); } }node; class union_find_tree{ private: static constexpr int N=100005; int n; queue<int> q1; vector<int> parent; vector<int> num; typedef long double D; public: vector<node> v1; void init(){ parent.assign(n,-1); num.assign(n,1); v1.assign(n,node()); } union_find_tree(int n_init){ assert(n_init>=0); n=n_init; init(); } union_find_tree(){ n=N; init(); } int check_parent(int x){ assert(x>=0 && x<n); if(parent[x]!=-1){ q1.push(x); return check_parent(parent[x]); } int a; while(!q1.empty()){ a=q1.front(),q1.pop(); parent[a]=x; } return x; } D connect(int x,int y){ assert(x>=0 && x<n); assert(y>=0 && y<n); x=check_parent(x),y=check_parent(y); if(x==y)return 0; if(num[x]>num[y])swap(x,y); parent[x]=y; num[y]+=num[x]; D s=-v1[x].calc()-v1[y].calc(); v1[y].connect(v1[x]); return s+v1[y].calc(); } int size(int pos){ pos=check_parent(pos); return num[pos]; } }; int main(){ int n,m; int i,j,k; int a,b,c; cin>>n; union_find_tree ua(n); for(i=0;i<n;i++)cin>>ua.v1[i].a; for(i=0;i<n;i++)cin>>ua.v1[i].b; for(i=0;i<n;i++)cin>>ua.v1[i].p; long double s=0; for(i=0;i<n;i++)s+=ua.v1[i].calc(); cin>>m; cout<<fixed<<setprecision(20); for(i=0;i<m;i++){ cin>>a>>b; a--,b--; s+=ua.connect(a,b); cout<<s<<endl; } }