Submission #1042299

# Submission time Handle Problem Language Result Execution time Memory
1042299 2024-08-02T19:55:15 Z Abito Sirni (COCI17_sirni) C++17
42 / 140
567 ms 786432 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
//#define int long long
#define ll long long
#define y1 YONE
typedef unsigned long long ull;
using namespace std;
const int N=1e7+5;
int a[N],n,par[N],sz[N];
int getpar(int x){
    if (x==par[x]) return x;
    return par[x]=getpar(par[x]);
}
void link(int x,int y){
    x=getpar(x);
    y=getpar(y);
    if (x==y) return;
    if (sz[x]>sz[y]) swap(x,y);
    sz[y]+=sz[x];
    par[x]=y;
    return;
}
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n;
    for (int i=1;i<=n;i++) cin>>a[i],par[i]=i,sz[i]=1;
    vector<vector<int>> v;
    for (int i=1;i<=n;i++){
        for (int j=i+1;j<=n;j++){
            v.pb({min(a[i]%a[j],a[j]%a[i]),i,j});
        }
    }
    sort(v.begin(),v.end());
    int ans=0;
    for (auto u:v){
        if (getpar(u[1])==getpar(u[2])) continue;
        link(u[1],u[2]);
        ans+=u[0];
    }cout<<ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 82 ms 29700 KB Output is correct
2 Correct 102 ms 31492 KB Output is correct
3 Correct 96 ms 31640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 30468 KB Output is correct
2 Correct 112 ms 32260 KB Output is correct
3 Correct 96 ms 31744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 31744 KB Output is correct
2 Correct 72 ms 27904 KB Output is correct
3 Correct 98 ms 31744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 554 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 517 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 546 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 557 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 567 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 529 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 550 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -