# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1092855 |
2024-09-25T09:06:25 Z |
vjudge1 |
Sirni (COCI17_sirni) |
C++14 |
|
413 ms |
111236 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 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++)
{
nxt[a[i]] = i;
for (int j = a[i] + 1; j < a[i + 1]; j++)
nxt[j] = i + 1;
}
for (int i = 1; i <= n; i++)
{
v.push_back({a[nxt[a[i] + 1]] % a[i], i, nxt[a[i] + 1]});
for (int mul = 2 * a[i]; mul <= a[n - 1]; mul += a[i])
{
v.push_back({a[nxt[mul]] % a[i], i, nxt[mul]});
mul = a[nxt[mul]] / a[i] * a[i];
}
}
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 |
Incorrect |
17 ms |
39516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
41 ms |
1360 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
39568 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
270 ms |
35888 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
41 ms |
12472 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
121 ms |
74628 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
19 ms |
12228 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
413 ms |
111236 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
409 ms |
110912 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
100 ms |
84948 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |