Submission #1061485

# Submission time Handle Problem Language Result Execution time Memory
1061485 2024-08-16T09:50:26 Z dimasnbayu Sirni (COCI17_sirni) C++14
42 / 140
551 ms 786432 KB
#include<bits/stdc++.h>
using namespace std;
const int sz=1e5+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

sirni.cpp: In function 'int main()':
sirni.cpp:30:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 38 ms 7116 KB Output is correct
2 Correct 49 ms 7628 KB Output is correct
3 Correct 44 ms 7372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 8140 KB Output is correct
2 Correct 57 ms 8396 KB Output is correct
3 Correct 44 ms 7624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 7624 KB Output is correct
2 Correct 35 ms 8648 KB Output is correct
3 Correct 48 ms 7116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 540 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 525 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 542 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 518 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 524 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 551 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 525 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -