Submission #1061484

#TimeUsernameProblemLanguageResultExecution timeMemory
1061484dimasnbayuSirni (COCI17_sirni)C++17
42 / 140
58 ms8652 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...