답안 #890715

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
890715 2023-12-21T19:05:50 Z aykhn Sirni (COCI17_sirni) C++17
84 / 140
1987 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});
        }
    }
    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';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 235348 KB Output is correct
2 Correct 157 ms 291924 KB Output is correct
3 Correct 73 ms 235604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 235244 KB Output is correct
2 Runtime error 732 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 235452 KB Output is correct
2 Correct 74 ms 235176 KB Output is correct
3 Correct 77 ms 235700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 174 ms 256500 KB Output is correct
2 Correct 450 ms 322428 KB Output is correct
3 Correct 233 ms 279852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 88 ms 239128 KB Output is correct
2 Correct 235 ms 281296 KB Output is correct
3 Correct 174 ms 256708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 306 ms 283860 KB Output is correct
2 Correct 560 ms 355064 KB Output is correct
3 Correct 234 ms 277040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 119 ms 242576 KB Output is correct
2 Correct 503 ms 354176 KB Output is correct
3 Correct 224 ms 279384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 199 ms 260868 KB Output is correct
2 Runtime error 1448 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 210 ms 270956 KB Output is correct
2 Runtime error 1346 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 239960 KB Output is correct
2 Runtime error 1987 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -