Submission #1092603

# Submission time Handle Problem Language Result Execution time Memory
1092603 2024-09-24T14:38:52 Z vjudge1 Sirni (COCI17_sirni) C++17
14 / 140
949 ms 66640 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 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;
        int d = a[i];
        a[i] = 0;
        while (d * k <= 1e7)
        {
            int x = lower_bound(a + 1, a + n + 1, k * d) - a;
            k = a[x] / d + 1;
            if (x == n + 1)
                break;
            v.push_back({a[x] % d, 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 600 KB Output is correct
2 Runtime error 48 ms 6476 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 39 ms 1364 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 476 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 335 ms 27948 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 43 ms 4524 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 949 ms 66640 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 44 ms 10676 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 427 ms 31968 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 394 ms 31616 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 57 ms 5564 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -