# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
66527 | 2018-08-11T10:05:37 Z | KLPP | Sirni (COCI17_sirni) | C++14 | 2926 ms | 787456 KB |
#include<iostream> #include<vector> #include<queue> #include<algorithm> #include<stdio.h> using namespace std; int parent[1000000]; int size[1000000]; void begin(int n){ for(int i=0;i<n;i++){ parent[i]=i; size[i]=1; } } int root(int x){ if(parent[x]==x)return x; parent[x]=root(parent[x]); return parent[x]; } bool component(int a, int b){ a=root(a); b=root(b); if(root(a)==root(b))return true; return false; } void merge(int a, int b){ a=root(a); b=root(b); if(a==b)return; if(size[a]<size[b]){ size[b]+=size[a]; parent[a]=b; return; } size[a]+=size[b]; parent[b]=a; } int main(){ int n; scanf("%d",&n); int arr[n]; for(int i=0;i<n;i++)scanf("%d",&arr[i]); sort(arr,arr+n); vector<pair<int,pair<int,int> > >Edges; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ Edges.push_back(pair<int,pair<int,int> >(arr[j]%arr[i],pair<int,int>(i,j))); } } sort(Edges.begin(),Edges.end()); begin(n); long long int ans=0; int CC=n; for(int i=0;i<Edges.size() && CC>1;i++){ int x,y; x=Edges[i].second.first; y=Edges[i].second.second; if(!component(x,y)){ merge(x,y); CC--; ans+=Edges[i].first; } //cout<<x<<" "<<y<<endl; }cout<<ans<<endl; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 56 ms | 6628 KB | Output is correct |
2 | Correct | 78 ms | 6740 KB | Output is correct |
3 | Correct | 63 ms | 6872 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 69 ms | 6880 KB | Output is correct |
2 | Correct | 81 ms | 6900 KB | Output is correct |
3 | Correct | 60 ms | 7040 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 64 ms | 7040 KB | Output is correct |
2 | Correct | 49 ms | 7040 KB | Output is correct |
3 | Correct | 61 ms | 7076 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 2725 ms | 787456 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 2584 ms | 787456 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 2926 ms | 787456 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 2855 ms | 787456 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 2665 ms | 787456 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 2892 ms | 787456 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 2760 ms | 787456 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |