Submission #668472

#TimeUsernameProblemLanguageResultExecution timeMemory
668472DoxenoSirni (COCI17_sirni)C++17
0 / 140
4978 ms612696 KiB
#include <vector> #include <algorithm> #include <iostream> #include <utility> #include <queue> #include <set> #define int long long using namespace std; signed main(){ int N; cin >> N; set<int> s; int a; for(int i = 0; i < N; ++i){ cin >> a; s.insert(-a); } N = s.size(); vector<int> v; for(auto x: s)v.emplace_back(-x); int m = 1e7 + 2; vector<vector<int>> p(m); for(int j = 0; j < N; ++j){ for(int i = 2*v[j]; i < m; i += v[j]){ p[i].push_back(j); } } int c = m-1; long long ans = 0; vector<vector<pair<int,int>>> adj(N); for(int i = 0; i < N; ++i){ auto x = v[i]; c = min(x, c); while(c > 0 && p[c].empty())--c; for(auto j: p[c]){ adj[j].emplace_back(make_pair(i, x-c)); adj[i].emplace_back(make_pair(j, x-c)); } } vector<int> vis(N, 0); vis[0] = 1; priority_queue<pair<int,int>> pq; for(auto [n, d]: adj[0])pq.push(make_pair(-d, n)); while(!pq.empty()){ auto [d, n] = pq.top(); pq.pop(); if(vis[n])continue; vis[n] = 1; ans -= d; for(auto [nn, dd]: adj[n]){ if(vis[nn])continue; pq.push(make_pair(-dd, nn)); } } cout << ans << endl; return 0; }
#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...