Submission #888582

#TimeUsernameProblemLanguageResultExecution timeMemory
888582asdasdqwerSirni (COCI17_sirni)C++14
0 / 140
888 ms134748 KiB
// #pragma GCC optimze("O3") // #pragma GCC target("avx,avx2,sse4") #include <bits/stdc++.h> using namespace std; #define int int64_t struct DSU { vector<int> p, r; DSU(int n) { p.assign(n,0); r.assign(n,0); for (int i=0;i<n;i++)p[i]=i; } int get(int i) { if (i != p[i]) p[i]=get(p[i]); return p[i]; } bool unite(int a,int b) { a=get(a); b=get(b); if (a==b)return false; if (r[a]<r[b])swap(a,b); p[b]=a; if (r[a]==r[b])r[a]++; return true; } }; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n;cin>>n; vector<int> a(n); for (int &x:a)cin>>x; sort(a.begin(),a.end()); vector<int> b; for (int x:a) { if (b.size()==0||b.back()!=x)b.push_back(x); } vector<int> clos(b.back()+1,-1); for (int x:b) { clos[x]=x; } for (int i=1;i<clos.size();i++) { clos[i]=max(clos[i], clos[i-1]); } typedef array<int,3> pii; vector<pii> edg; for (int x:b) { vector<pii> tmp; for (int j=2*x;j<=b.back();j+=x) { if (clos[j] != -1) { if (!tmp.size()) { tmp.push_back({clos[j] % x, clos[j], x}); } else if (tmp.back()[1] != clos[j]) { tmp.push_back({clos[j] % x, clos[j], x}); } } } if (tmp.size() == 0 || tmp.back()[1] != clos[b.back()]) { tmp.push_back({clos[b.back()] % x, clos[b.back()], x}); } for (auto x:tmp) edg.push_back(x); } sort(edg.begin(),edg.end()); map<int,int> mp; for (int i=0;i<b.size();i++) { mp[b[i]]=i; } for (auto &x:edg) { x[1]=mp[x[1]]; x[2]=mp[x[2]]; } DSU d(b.size()); int cost=0; for (auto x:edg) { if (d.unite(x[1], x[2])) { // cout<<b[x[1]]<<" "<<b[x[2]]<<"\n"; cost+=x[0]; } } cout<<cost<<"\n"; }

Compilation message (stderr)

sirni.cpp: In function 'int main()':
sirni.cpp:51:19: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for (int i=1;i<clos.size();i++) {
      |                  ~^~~~~~~~~~~~
sirni.cpp:80:19: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     for (int i=0;i<b.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...