답안 #942422

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
942422 2024-03-10T15:58:26 Z trMatherz Sirni (COCI17_sirni) C++17
42 / 140
688 ms 786432 KB
#include <iostream> //cin, cout

/*
#include <fstream>
std::ifstream cin ("ex.in");
std::ofstream cout ("ex.out");
*/

// includes
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <unordered_set>
#include <stack>
#include <ext/pb_ds/assoc_container.hpp>
#include <random>
#include <chrono>
#include <bitset>
#include <complex>

// usings
using namespace std;
using namespace __gnu_pbds;

// misc
#define ll long long
#define ld long double
#define pb push_back
#define pq priority_queue
#define ub upper_bound
#define lb lower_bound
template <typename T, typename U>
bool emin(T &a, const U &b) { return b < a ? a = b, true : false; }
template <typename T, typename U>
bool emax(T &a, const U &b) { return b > a ? a = b, true : false; }
typedef uint64_t hash_t;

// vectors
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define vpii vector<pair<int, int>>
#define vvpii vector<vector<pair<int, int>>>
#define vppipi vector<pair<int, pair<int, int>>>
#define vl vector<ll>
#define vvl vector<vl>
#define vvvl vector<vvl>
#define vpll vector<pair<ll, ll>>
#define vvpll vector<vpll>
#define vb vector<bool>
#define vvb vector<vb>
#define vs vector<string>
#define sz(x) (int)x.size()
#define rz resize
#define all(x) x.begin(), x.end()

// pairs
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define f first
#define s second

// sets
#define si set<int>
#define sl set<ll>
#define ss set<string>
#define in insert
template <class T>
using iset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// maps
#define mii map<int, int>
#define mll map<ll, ll>

// loops
#define FR(x, z, y) for (int x = z; x < y; x++)
#define FRE(x, z, y) FR(x, z, y + 1)
#define F(x, y) FR(x, 0, y)
#define FE(x, y) F(x, y + 1)
#define A(x, y) for (auto &x : y)



vi dsu; 

int get(int x){ return dsu[x] < 0 ? x : dsu[x] = get(dsu[x]);}

bool merge(int x, int y){
    x = get(x), y = get(y);
    if(x == y) return false;
    if(dsu[x] > dsu[y]) swap(x, y);
    dsu[x] += dsu[y];
    dsu[y] = x;
    return true;
}

int main()
{
    int n; cin >> n;
    dsu = vi(n, -1);
    vi a(n); A(u, a) cin >> u;
    ll tot = 0;
    vector<array<int, 3>> v;
    sort(all(a));
    vi b = {a[0]};
    FR(i, 1, n){
        A(u, b) if(a[i] % u == 0) continue;
        b.pb(a[i]);
    }

    F(i, sz(b)){
        FR(j, i + 1, sz(b)){
            v.pb({min(b[i] % b[j], b[j] % b[i]), i, j});
        }
    }
    sort(all(v), [](auto p, auto o){return p[0] < o[0];});
    A(u, v){
        if(merge(u[1], u[2])) tot += u[0];
    }
    cout << tot;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 7628 KB Output is correct
2 Correct 33 ms 8140 KB Output is correct
3 Correct 40 ms 6860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 8392 KB Output is correct
2 Correct 29 ms 7372 KB Output is correct
3 Correct 46 ms 8392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 8648 KB Output is correct
2 Correct 30 ms 8140 KB Output is correct
3 Correct 41 ms 7372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 688 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 635 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 669 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 634 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 666 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 665 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 644 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -