# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1092832 |
2024-09-25T08:25:05 Z |
vjudge1 |
Sirni (COCI17_sirni) |
C++14 |
|
934 ms |
190656 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 == n + 1)
x = -1;
}
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 |
Correct |
25 ms |
43344 KB |
Output is correct |
2 |
Runtime error |
118 ms |
89792 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
89 ms |
80728 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
43612 KB |
Output is correct |
2 |
Correct |
23 ms |
42064 KB |
Output is correct |
3 |
Correct |
26 ms |
43572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
362 ms |
115104 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
96 ms |
91836 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
934 ms |
153792 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
107 ms |
91572 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
507 ms |
190656 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
510 ms |
190312 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
152 ms |
154244 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |