# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
715211 | murad_2005 | Sirni (COCI17_sirni) | C++14 | 803 ms | 786432 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define piii pair<int, pii>
#define pllll pair<ll, ll>
#define plli pair<ll, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define size(v) v.size()
#define INF 1e9
#define f first
#define s second
#define ln "\n"
using namespace std;
const int up = 1e5 + 5;
int sz[up], parent[up];
void make_set(int u){
sz[u] = 1, parent[u] = u;
}
int find_set(int u){
if(u == parent[u]) return u;
return parent[u] = find_set(parent[u]);
}
void union_set(int u, int v){
int a = find_set(u);
int b = find_set(v);
if(a != b){
if(sz[a] < sz[b]){
swap(a, b);
}
parent[b] = a;
sz[a] += b;
}
}
void solve(){
int n;
cin >> n;
vector<int>p(n + 1);
for(int i = 1; i <= n; ++i){
cin >> p[i];
make_set(i);
}
vector<piii>edges;
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; j++){
if(i != j){
int val = min(p[i] % p[j], p[j] % p[i]);
edges.pb({val, {i, j}});
}
}
}
sort(all(edges));
ll Res = 0;
for(int i = 0; i < size(edges); ++i){
int u = edges[i].s.f;
int v = edges[i].s.s;
int val = edges[i].f;
if(find_set(u) != find_set(v)){
Res += val;
union_set(u, v);
}
}
cout << Res << "\n";
}
int main(){
int t;
t = 1;
// cin >> t;
while(t--){
solve();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |