Submission #862658

# Submission time Handle Problem Language Result Execution time Memory
862658 2023-10-18T18:11:44 Z Irate Sirni (COCI17_sirni) C++14
42 / 140
44 ms 8652 KB
#include<bits/stdc++.h>
using namespace std;
const int mxN = 1e3 + 3;
int a[mxN];
struct Edge{
    int u, v, w;
    bool operator<(Edge &other){
        return w < other.w;
    }
};
struct DSU{
    vector<int>par;
    DSU(int n){
        par.assign(n + 1, -1);
    }
    int FindRep(int u){
        if(par[u] < 0)return u;
        return par[u] = FindRep(par[u]);
    }
    bool Union(int u, int v){
        u = FindRep(u);
        v = FindRep(v);
        if(u == v)return false;
        if(par[u] > par[v])swap(u, v);
        par[u] += par[v];
        par[v] = u;
        return true;
    }
};
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 1;i <= n;++i){
        cin >> a[i];
    }
    vector<Edge>edge_list;
    for(int i = 1;i <= n;++i){
        for(int j = i + 1;j <= n;++j){
            Edge temp;
            temp.u = i;
            temp.v = j;
            temp.w = max(a[i], a[j]) % min(a[i], a[j]);
            edge_list.push_back(temp);
        }
    }
    sort(edge_list.begin(), edge_list.end());
    DSU dsu(n);
    long long res = 0;
    for(int i = 0;i < edge_list.size();++i){
        if(dsu.Union(edge_list[i].u, edge_list[i].v))res += edge_list[i].w;
    }
    cout << res;
}

Compilation message

sirni.cpp: In function 'int main()':
sirni.cpp:52:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(int i = 0;i < edge_list.size();++i){
      |                   ~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 39 ms 7372 KB Output is correct
2 Correct 37 ms 6856 KB Output is correct
3 Correct 44 ms 8652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 8140 KB Output is correct
2 Correct 31 ms 7372 KB Output is correct
3 Correct 44 ms 7884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 7372 KB Output is correct
2 Correct 34 ms 7884 KB Output is correct
3 Correct 43 ms 7880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -