# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1092829 |
2024-09-25T08:22:13 Z |
vjudge1 |
Sirni (COCI17_sirni) |
C++14 |
|
792 ms |
786432 KB |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
struct pi
{
int w, u, v;
};
bool cmp(pi a, pi b)
{
if (a.w <= b.w)
return true;
return false;
}
int par[100005];
int fid(int x)
{
if (par[x] == x)
return x;
return par[x] = fid(par[x]);
}
void make_pair(int x, int y)
{
int u = fid(x);
int v = fid(y);
if (u == v)
return;
if (u < v)
swap(u, v);
par[u] = v;
}
vector<pi> v;
int mp[10000007], nxt[10000007];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
par[i] = i;
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++)
mp[a[i]] = i;
int k = -1;
for (int i = 10000002; i >= 0; i--)
{
if (mp[i] != 0)
k = mp[i];
nxt[i] = k;
}
for (int i = 1; i <= n; i++)
{
k = 1;
while (a[i] * k <= 10000000)
{
int x = nxt[a[i] * k];
if (x == i)
x++;
if (x == -1)
break;
v.push_back({a[x] % a[i], i, x});
k = a[x] / a[i] + 1;
// cout << i << " " << x << " " << a[x] % a[i] << '\n';
}
}
sort(v.begin(), v.end(), cmp);
long long ans = 0;
for (auto x : v)
{
if (fid(x.u) == fid(x.v))
continue;
make_pair(x.u, x.v);
ans += x.w;
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
736 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
745 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
746 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
740 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
769 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
792 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
740 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
782 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
788 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
712 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |