Submission #168489

#TimeUsernameProblemLanguageResultExecution timeMemory
168489theStaticMindSirni (COCI17_sirni)C++14
0 / 140
2148 ms105804 KiB
#include<bits/stdc++.h> #define mp make_pair #define pb push_back #define ii pair<int,int> #define all(x) (x).begin(),(x).end() #define INF 100000000000000000 #define modulo 1000000007 #define mod 998244353 #define int long long int using namespace std; priority_queue<pair<int,ii>,vector<pair<int,ii>>,greater<pair<int,ii>>>edge; vector<int>no(1000005); int F(int x){ if(no[x]==x)return x; return no[x]=F(no[x]); } bool merge(int x,int y){ x=F(x); y=F(y); if(x==y)return false; no[x]=y; return true; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("q.gir","r",stdin); // freopen("q.cik","w",stdout); int n,ans=0; cin>>n; for(int i=0;i<=n;i++)no[i]=i; vector<int>A(n); for(int i=0;i<n;i++)cin>>A[i]; sort(all(A)); vector<int>arr; arr.pb(A[0]); for(int i=1;i<n;i++){ if(A[i]!=A[i-1])arr.pb(A[i]); } map<int,vector<int>> data; for(int i=0;i*arr[0]<=1e6;i++){ data[arr[0]*i].pb(0); } for(int i=1;i<arr.size();i++){ map<int,vector<int>>::iterator itr; vector<int>& Q=(itr=--data.upper_bound(arr[i]))->second; for(int j=0;j<Q.size();j++){ edge.push({arr[i]-itr->first,{i,Q[j]}}); } for(int j=1;j*arr[i]<=1e6;j++){ data[arr[i]*j].pb(i); } } while(!edge.empty()){ int x=edge.top().second.first; int y=edge.top().second.second; int w=edge.top().first; edge.pop(); if(merge(x,y)){ ans+=w; } } cout<<ans; }

Compilation message (stderr)

sirni.cpp: In function 'int32_t main()':
sirni.cpp:44:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int i=1;i<arr.size();i++){
                   ~^~~~~~~~~~~
sirni.cpp:47:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j=0;j<Q.size();j++){
                         ~^~~~~~~~~
#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...