Submission #890716

# Submission time Handle Problem Language Result Execution time Memory
890716 2023-12-21T19:06:10 Z aykhn Sirni (COCI17_sirni) C++17
112 / 140
2274 ms 786432 KB
#include <bits/stdc++.h>
 
// author : aykhn
 
using namespace std;
typedef long long ll;
 
#define pb push_back
#define ins insert
#define mpr make_pair
#define all(v) v.begin(), v.end()
#define bpc __builtin_popcountll
#define pii pair<ll, ll>
#define pll pair<ll, ll>
#define fi first
#define se second
#define int ll
#define infll 0x3F3F3F3F3F3F3F3F
#define inf 0x3F3F3F3F
 
struct DSU
{
    vector<int> e;
    void init(int n)
    {
        e.assign(n + 1, -1);
    }
    int get(int x)
    {
        if (e[x] < 0) return x;
        return e[x] = get(e[x]);
    }
    int tog(int x, int y)
    {
        return get(x) == get(y);
    }
    int unite(int x, int y)
    {
        x = get(x);
        y = get(y);
        if (x == y) return 0;
        if (e[x] > e[y]) swap(x, y);
        e[x] += e[y];
        e[y] = x;
        return 1;
    }
};
 
const int MXN = 5e5 + 5;

vector<array<int, 2>> e[10000005];
 
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    int a[n + 1];
    a[0] = 0;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++)
    {
        if (a[i] == a[i - 1]) continue;
        for (int j = a[i]; j <= a[n]; j += a[i])
        {
            int ind = (j == a[i] ? upper_bound(a + 1, a + n + 1, j) - a : lower_bound(a + 1, a + n + 1, j) - a);
            if (ind > n) break;
            e[a[ind]%a[i]].pb({i, ind});
          j = a[ind]/a[i]*a[i];
        }
    }
    int res = 0;
    DSU dsu;
    dsu.init(n);
    for (int i = 0; i < 10000005; i++)
    {
        for (array<int, 2> a : e[i]) if (dsu.unite(a[0], a[1])) res += i;
    }
    cout << res << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 78 ms 235440 KB Output is correct
2 Correct 85 ms 240132 KB Output is correct
3 Correct 72 ms 235648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 235320 KB Output is correct
2 Correct 77 ms 236636 KB Output is correct
3 Correct 71 ms 235348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 235440 KB Output is correct
2 Correct 74 ms 235308 KB Output is correct
3 Correct 75 ms 235500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 190 ms 255472 KB Output is correct
2 Correct 453 ms 314032 KB Output is correct
3 Correct 209 ms 266556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 238564 KB Output is correct
2 Correct 242 ms 279140 KB Output is correct
3 Correct 175 ms 256768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 332 ms 284796 KB Output is correct
2 Correct 540 ms 344080 KB Output is correct
3 Correct 216 ms 263176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 242064 KB Output is correct
2 Correct 468 ms 328704 KB Output is correct
3 Correct 197 ms 262480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 200 ms 258648 KB Output is correct
2 Correct 1835 ms 687528 KB Output is correct
3 Correct 223 ms 264116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 194 ms 259680 KB Output is correct
2 Runtime error 2274 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 92 ms 239956 KB Output is correct
2 Runtime error 2239 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -