제출 #949284

#제출 시각아이디문제언어결과실행 시간메모리
949284vjudge1Sirni (COCI17_sirni)C++17
42 / 140
584 ms786432 KiB
#include <bits/stdc++.h> #define ll long long #define str string #define ins insert #define ld long double #define pb push_back #define pf push_front #define pof pop_front() #define pob pop_back() #define lb lower_bound #define ub upper_bound #define endl "\n" #define fr first #define sc second #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define sz size() #define vll vector<ll> #define bc back() #define arr array #define pll vector<pair<ll,ll>> using namespace std;/* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>*/ template<class S,class T> bool chmin(S &a,const T &b) { return a>b?(a=b)==b:false; } template<class S,class T> bool chmax(S &a,const T &b) { return a<b?(a=b)==b:false; } void start(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const ll N=1e5+5; const ll M=1e7+5; ll siz[N],p[N]; vll v(1); ll anc(ll a){ return (a==p[a] ? a : p[a]=anc(p[a])); } bool uni(ll a,ll b){ a=anc(a); b=anc(b); if(a==b) return false; if(siz[a]>siz[b])swap(a,b); siz[b]+=siz[a]; p[a]=b; return true; } void solve(){ ll i,j; ll n,sum=0; cin>>n; ll a; set<ll> st; for(i=0;i<n;i++){ cin>>a; p[i+1]=i+1; siz[i+1]=1; st.ins(a); } n=st.sz; for(auto i : st) v.pb(i); vector<pair<ll,pair<ll,ll>>> e; for(i=1;i<=n;i++){ for(j=i+1;j<=n;j++){ e.pb({v[j]%v[i],{i,j}}); } } sort(all(e)); ll c=n-1,ans=0; for(i=0;i<e.sz;i++){ if(uni(e[i].sc.fr,e[i].sc.sc)){c--;ans+=e[i].fr;} if(!c) break; } cout<<ans<<endl; } signed main(){ start(); ll t=1; //cin>>t; while(t--) solve(); return 0; } /* */

컴파일 시 표준 에러 (stderr) 메시지

sirni.cpp: In function 'void solve()':
sirni.cpp:78:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for(i=0;i<e.sz;i++){
      |              ^
sirni.cpp:58:10: warning: unused variable 'sum' [-Wunused-variable]
   58 |     ll n,sum=0;
      |          ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...