답안 #890706

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
890706 2023-12-21T18:56:13 Z aykhn Sirni (COCI17_sirni) C++17
84 / 140
1416 ms 786436 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;
 
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);
    vector<array<int, 3>> e;
    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.pb({a[ind] % a[i], i, ind});
        }
    }
    sort(all(e));
    int res = 0;
    DSU dsu;
    dsu.init(n);
    for (int i = 0; i < e.size(); i++)
    {
        if (dsu.unite(e[i][1], e[i][2])) res += e[i][0];
    }
    cout << res << '\n';
}

Compilation message

sirni.cpp: In function 'int main()':
sirni.cpp:76:23: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |     for (int i = 0; i < e.size(); i++)
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 328 ms 99484 KB Output is correct
3 Correct 4 ms 1368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Runtime error 536 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 2 ms 796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 266 ms 51520 KB Output is correct
2 Correct 1020 ms 102092 KB Output is correct
3 Correct 480 ms 101548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 7368 KB Output is correct
2 Correct 452 ms 101996 KB Output is correct
3 Correct 276 ms 52128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 581 ms 101088 KB Output is correct
2 Correct 1416 ms 200396 KB Output is correct
3 Correct 405 ms 51368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 15300 KB Output is correct
2 Correct 1335 ms 200400 KB Output is correct
3 Correct 415 ms 52408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 317 ms 51876 KB Output is correct
2 Runtime error 702 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 389 ms 51384 KB Output is correct
2 Runtime error 636 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 7108 KB Output is correct
2 Runtime error 967 ms 786436 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -