Submission #1092817

# Submission time Handle Problem Language Result Execution time Memory
1092817 2024-09-25T07:56:04 Z vjudge1 Sirni (COCI17_sirni) C++17
0 / 140
1053 ms 190596 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 = 10000000; i >= 1; i--)
    {
        if (mp[i] != 0)
            k = mp[i];
        nxt[i] = k;
    }
    for (int i = 1; i <= n; i++)
    {
        k = 1;
        while (a[i] * k <= 1e7)
        {
            int x = nxt[a[i] * k];
            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 99 ms 88404 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 122 ms 80724 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 106 ms 88912 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 237 ms 115108 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 84 ms 91920 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1053 ms 154128 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 70 ms 91792 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 415 ms 190596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 432 ms 190260 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 125 ms 154296 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -