Submission #1092600

# Submission time Handle Problem Language Result Execution time Memory
1092600 2024-09-24T14:36:29 Z vjudge1 Sirni (COCI17_sirni) C++17
14 / 140
917 ms 66720 KB
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100001];
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 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++)
    {
        int k = 1;
        while (a[i] * k <= 1e7)
        {
            int x = lower_bound(a + i + 1, a + n + 1, k * a[i]) - a;
            k = a[x] / a[i] + 1;
            if (x == n + 1)
                break;
            v.push_back({a[x] % a[i], i, x});
            //  cout << i << " " << x << '\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 1 ms 604 KB Output is correct
2 Runtime error 47 ms 6460 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 1112 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 328 ms 27880 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 42 ms 4540 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 917 ms 66720 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 35 ms 10632 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 419 ms 32000 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 388 ms 31584 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 51 ms 5572 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -