# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
248069 |
2020-07-12T07:53:36 Z |
NONAME |
Sirni (COCI17_sirni) |
C++14 |
|
910 ms |
786436 KB |
#include <bits/stdc++.h>
#define dbg(x) cerr << #x << " = " << x << "\n"
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie()
using namespace std;
using ll = long long;
const int N = int(1e5) + 10;
int n, a[N], pr[N];
ll ans;
vector <pair <ll, pair <int, int> > > v;
int f(int x) { return (x == pr[x]) ? x : pr[x] = f(pr[x]); }
int main() {
fast_io;
cin >> n;
for (int i = 0; i < n; ++i)
cin >> a[i], pr[i] = i;
for (int i = 0; i < n; ++i)
for (int j = i + 1; j < n; ++j)
v.push_back(make_pair(max(a[i], a[j]) % min(a[i], a[j]), make_pair(i, j)));
sort(v.begin(), v.end());
for (int i = 0; i < int(v.size()); ++i) {
int x = v[i].second.first, y = v[i].second.second;
x = f(x);
y = f(y);
if (x == y)
continue;
ans += v[i].first;
pr[y] = x;
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
8688 KB |
Output is correct |
2 |
Correct |
71 ms |
8688 KB |
Output is correct |
3 |
Correct |
67 ms |
8688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
8688 KB |
Output is correct |
2 |
Correct |
81 ms |
8688 KB |
Output is correct |
3 |
Correct |
66 ms |
8688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
8688 KB |
Output is correct |
2 |
Correct |
60 ms |
8688 KB |
Output is correct |
3 |
Correct |
69 ms |
8688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
894 ms |
786436 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
870 ms |
786436 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
891 ms |
786436 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
881 ms |
786436 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
888 ms |
786436 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
910 ms |
786436 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
889 ms |
786436 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |