Submission #715205

# Submission time Handle Problem Language Result Execution time Memory
715205 2023-03-26T08:16:01 Z murad_2005 Sirni (COCI17_sirni) C++14
42 / 140
148 ms 12736 KB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define piii pair<int, pii>
#define pllll pair<ll, ll>
#define plli pair<ll, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define size(v) v.size()
#define INF 1e9
#define f first
#define s second
#define ln "\n"

using namespace std;

const int up = 1e3 + 5;

int sz[up], parent[up];

void make_set(int u){
    sz[u] = 1, parent[u] = u;
}

int find_set(int u){
    if(u == parent[u]) return u;
    return parent[u] = find_set(parent[u]);
}

void union_set(int u, int v){
    int a = find_set(u);
    int b = find_set(v);
    if(a != b){
        if(sz[a] < sz[b]){
            swap(a, b);
        }
        parent[b] = a;
        sz[a] += b;
    }
}

void solve(){
    int n;
    cin >> n;
    vector<int>p(n + 1);
    for(int i = 1; i <= n; ++i){
        cin >> p[i];
        make_set(i);
    }
    vector<piii>edges;
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= n; j++){
            if(i != j){
                int val = min(p[i] % p[j], p[j] % p[i]);
                edges.pb({val, {i, j}});
            }
        }
    }
    sort(all(edges));
    ll Res = 0;
    for(int i = 0; i < size(edges); ++i){
        int u = edges[i].s.f;
        int v = edges[i].s.s;
        int val = edges[i].f;
        if(find_set(u) != find_set(v)){
            Res += val;
            union_set(u, v);
        }
    }
    cout << Res << "\n";

}

int main(){
    int t;
    t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Compilation message

sirni.cpp: In function 'void solve()':
sirni.cpp:64:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     for(int i = 0; i < size(edges); ++i){
      |                      ^
# Verdict Execution time Memory Grader output
1 Correct 107 ms 12736 KB Output is correct
2 Correct 138 ms 12708 KB Output is correct
3 Correct 129 ms 12736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 147 ms 12652 KB Output is correct
2 Correct 148 ms 12676 KB Output is correct
3 Correct 125 ms 12652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 12680 KB Output is correct
2 Correct 97 ms 12736 KB Output is correct
3 Correct 123 ms 12668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1108 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 1220 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 724 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1236 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1236 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -