Submission #345964

#TimeUsernameProblemLanguageResultExecution timeMemory
345964AmineTrabelsiSirni (COCI17_sirni)C++14
42 / 140
1117 ms786436 KiB
#include "bits/stdc++.h" using namespace std; // Hi int main(){ ios::sync_with_stdio(0);cin.tie(0); // for 20% int n; cin>>n; vector<int> a(n),parent(n); for(auto &i:a)cin>>i; for(int i=0;i<n;i++){ parent[i] =i; } auto find = [&](int x){ while(x != parent[x])x = parent[x]; return x; }; auto unite = [&](int a,int b){ a = find(a); b = find(b); if(a != b){ parent[b] = a; } }; vector<pair<int,pair<int,int>>> edges; for(int i=0;i<n;i++){ for(int j=0;j<i;j++){ edges.push_back({min(a[i]%a[j],a[j]%a[i]),{i,j}}); } } long long res = 0; sort(edges.begin(),edges.end()); for(auto edge:edges){ int x = edge.second.first,b = edge.second.second; if(find(x) != find(b)){ res += edge.first; unite(x,b); } } cout << res <<'\n'; return 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...