답안 #345964

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
345964 2021-01-08T18:18:39 Z AmineTrabelsi Sirni (COCI17_sirni) C++14
42 / 140
1117 ms 786436 KB
#include "bits/stdc++.h"
using namespace std;
// Hi 

int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    // for 20%
    int n;
    cin>>n;
    vector<int> a(n),parent(n);
    for(auto &i:a)cin>>i;
    for(int i=0;i<n;i++){
        parent[i] =i;
    }
    auto find = [&](int x){
        while(x != parent[x])x = parent[x];
        return x;
    };
    auto unite = [&](int a,int b){
        a = find(a);
        b = find(b);
        if(a != b){
            parent[b] = a;
        }
    };
    vector<pair<int,pair<int,int>>> edges;
    for(int i=0;i<n;i++){
        for(int j=0;j<i;j++){
            edges.push_back({min(a[i]%a[j],a[j]%a[i]),{i,j}});
        }
    }
    long long res = 0;
    sort(edges.begin(),edges.end());
    for(auto edge:edges){
        int x = edge.second.first,b = edge.second.second;
        if(find(x) != find(b)){
            res += edge.first;
            unite(x,b);
        }
    }
    cout << res <<'\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 353 ms 6620 KB Output is correct
2 Correct 485 ms 6620 KB Output is correct
3 Correct 699 ms 6620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 600 ms 6620 KB Output is correct
2 Correct 1025 ms 6620 KB Output is correct
3 Correct 746 ms 6620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 463 ms 6620 KB Output is correct
2 Correct 235 ms 6620 KB Output is correct
3 Correct 532 ms 6620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1117 ms 786436 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1016 ms 786436 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1012 ms 786432 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1020 ms 786436 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1020 ms 786436 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1022 ms 786436 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1000 ms 786436 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -