Submission #942418

# Submission time Handle Problem Language Result Execution time Memory
942418 2024-03-10T15:54:12 Z trMatherz Sirni (COCI17_sirni) C++17
42 / 140
801 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;
    F(i, n){
        FR(j, i + 1, n){
            v.pb({min(a[i] % a[j], a[j] % a[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;
}
# Verdict Execution time Memory Grader output
1 Correct 44 ms 8396 KB Output is correct
2 Correct 44 ms 6860 KB Output is correct
3 Correct 50 ms 6856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 7372 KB Output is correct
2 Correct 36 ms 8140 KB Output is correct
3 Correct 52 ms 7116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 8392 KB Output is correct
2 Correct 50 ms 7880 KB Output is correct
3 Correct 52 ms 6856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 801 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 639 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 654 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 625 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 633 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 630 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 629 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -