結果
問題 | 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
|
実行時間 | 770 ms / 2,000 ms |
コード長 | 3,027 bytes |
コンパイル時間 | 1,046 ms |
コンパイル使用メモリ | 107,920 KB |
実行使用メモリ | 8,960 KB |
最終ジャッジ日時 | 2024-06-09 09:57:12 |
合計ジャッジ時間 | 30,092 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 3 ms
5,376 KB |
testcase_08 | AC | 3 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 66 ms
5,376 KB |
testcase_14 | AC | 46 ms
5,376 KB |
testcase_15 | AC | 13 ms
5,376 KB |
testcase_16 | AC | 12 ms
5,376 KB |
testcase_17 | AC | 40 ms
5,376 KB |
testcase_18 | AC | 24 ms
5,376 KB |
testcase_19 | AC | 65 ms
5,376 KB |
testcase_20 | AC | 56 ms
5,376 KB |
testcase_21 | AC | 58 ms
5,376 KB |
testcase_22 | AC | 53 ms
5,376 KB |
testcase_23 | AC | 158 ms
6,016 KB |
testcase_24 | AC | 320 ms
6,912 KB |
testcase_25 | AC | 621 ms
7,040 KB |
testcase_26 | AC | 433 ms
6,656 KB |
testcase_27 | AC | 503 ms
5,376 KB |
testcase_28 | AC | 250 ms
5,376 KB |
testcase_29 | AC | 179 ms
5,376 KB |
testcase_30 | AC | 770 ms
7,296 KB |
testcase_31 | AC | 695 ms
8,320 KB |
testcase_32 | AC | 384 ms
7,680 KB |
testcase_33 | AC | 623 ms
5,888 KB |
testcase_34 | AC | 498 ms
5,632 KB |
testcase_35 | AC | 294 ms
6,912 KB |
testcase_36 | AC | 585 ms
8,064 KB |
testcase_37 | AC | 123 ms
5,376 KB |
testcase_38 | AC | 169 ms
7,168 KB |
testcase_39 | AC | 741 ms
6,968 KB |
testcase_40 | AC | 749 ms
6,784 KB |
testcase_41 | AC | 550 ms
7,424 KB |
testcase_42 | AC | 518 ms
5,376 KB |
testcase_43 | AC | 2 ms
5,376 KB |
testcase_44 | AC | 394 ms
8,960 KB |
testcase_45 | AC | 460 ms
5,376 KB |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/vector:64, from main.cpp:5: In member function '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: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_vector.h:804:23: warning: '<anonymous>' may be used uninitialized [-Wmaybe-uninitialized] 804 | { _M_fill_assign(__n, __val); } | ~~~~~~~~~~~~~~^~~~~~~~~~~~ In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/vector:70: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/vector.tcc: In constructor 'union_find_tree::union_find_tree(int)': /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/vector.tcc:264:5: note: 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: note: '<anonymous>' declared here 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; } }