Submission #890043

# Submission time Handle Problem Language Result Execution time Memory
890043 2023-12-20T12:08:30 Z codefox Sirni (COCI17_sirni) C++17
0 / 140
4587 ms 605976 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pii pair<int, int>
#define f first
#define s second

vector<int> rep;

int finde(int i)
{
    if (i != rep[i]) rep[i] = finde(rep[i]);
    return rep[i];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> nums;
    vector<int> mult(1e7+1, -1);
    vector<bool> vis(1e7+1, 0);
    for(int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        if (vis[a]) continue;
        vis[a] = true;
        nums.push_back(a);
    }
    sort(nums.begin(), nums.end());
    ll sol = 0;
    n = nums.size();

    int curr = 0;
    int val = -1;
    for (int i = 0; i < n; i++)
    {
        int ele = nums[i];
        while (curr < ele)
        {
            mult[curr] = val;
            curr++;
        }
        val = i;
    }
    while (curr <= 1e7)
    {
        mult[curr] = val;
        curr++;
    }

    vector<vector<pii>> dist(1e7+1);
    rep = vector<int>(n);
    iota(rep.begin(), rep.end(), 0);

    for (int i = 0; i < n; i++)
    {
        for (int j = nums[i]; j <= 1e7; j+=nums[i])
        {
            int best = mult[j];
            if (best != -1) dist[j-nums[best]].push_back({i, best});
        }
    }

    for (int i = 0; i <= 1e7; i++)
    {
        for (pii ele:dist[i])
        {
            if (finde(ele.f) !=finde(ele.s))
            {
                sol+=i;
                rep[finde(ele.f)]=finde(ele.s);
            }
        }
    }
    cout << sol;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 104 ms 275808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1607 ms 430652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 89 ms 275804 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2785 ms 457384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 515 ms 320644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4587 ms 605976 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4153 ms 577396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 171 ms 290164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 158 ms 294624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 100 ms 278100 KB Output isn't correct
2 Halted 0 ms 0 KB -