Submission #1092866

# Submission time Handle Problem Language Result Execution time Memory
1092866 2024-09-25T09:21:06 Z vjudge1 Sirni (COCI17_sirni) C++14
0 / 140
260 ms 65112 KB
#include <bits/stdc++.h>
using namespace std;
int n;
const int MAN = 1e5;
const int MAP = 1e7;
vector<int> a;
struct pi
{
    int w, u, v;
};
bool cmp(pi a, pi b)
{
    if (a.w < b.w)
        return true;
    return false;
}
int par[MAN + 5];
int fid(int x)
{
    if (par[x] == x)
        return x;
    return par[x] = fid(par[x]);
}
bool make_pair(int x, int y)
{
    int u = fid(x);
    int v = fid(y);

    if (u == v)
        return false;
    par[v] = u;
    return true;
}
vector<pi> v;
int nxt[MAP + 5];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        par[i] = i;
    sort(a.begin(), a.end());
    for (int i = 0; i < n - 1; i++)
    {
        nxt[a[i]] = i;
        for (int j = a[i] + 1; j < a[i + 1]; j++)
            nxt[j] = i + 1;
    }
    nxt[a[n - 1]] = n - 1;
    for (int i = 0; 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);
    int ans = 0;
    for (auto x : v)
    {
        if (make_pair(x.u, x.v))
            ans += x.w;
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 39512 KB Output is correct
2 Incorrect 45 ms 42448 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 39516 KB Output is correct
2 Incorrect 17 ms 39520 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 109 ms 17624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 7632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 260 ms 54408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 7628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 178 ms 65112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 180 ms 64948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 42952 KB Output isn't correct
2 Halted 0 ms 0 KB -