# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1061484 | 2024-08-16T09:49:52 Z | dimasnbayu | Sirni (COCI17_sirni) | C++17 | 58 ms | 8652 KB |
#include<bits/stdc++.h> using namespace std; const int sz=1e3+5; int par[sz],arr[sz]; vector<pair<int,pair<int,int>>> v; int find(int x){ if(par[x]==x) return x; else return par[x]=find(par[x]); } void merge(int x, int y){ x=find(x),y=find(y); par[x]=y; } bool check(int x, int y){ return find(x)==find(y); } int main(){ int n; cin>>n; for(int i=1;i<=n;i++){ cin>>arr[i]; par[i]=i; } for(int i=1;i<=n;i++){ for(int j=i+1;j<=n;j++){ v.push_back({min(arr[i]%arr[j],arr[j]%arr[i]),{i,j}}); } } sort(v.begin(),v.end()); int ans=0; for(int i=0;i<v.size();i++){ // cout<<v[i].first<<" "<<v[i].second.first<<" "<<v[i].second.second<<endl; if(!check(v[i].second.first,v[i].second.second)){ ans+=v[i].first; merge(v[i].second.first,v[i].second.second); } } cout<<ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 38 ms | 6856 KB | Output is correct |
2 | Correct | 49 ms | 7628 KB | Output is correct |
3 | Correct | 45 ms | 7112 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 50 ms | 8652 KB | Output is correct |
2 | Correct | 58 ms | 8140 KB | Output is correct |
3 | Correct | 44 ms | 8652 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 43 ms | 7880 KB | Output is correct |
2 | Correct | 35 ms | 7628 KB | Output is correct |
3 | Correct | 44 ms | 7112 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 | 2 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 | 604 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 | 604 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |