Submission #887145

#TimeUsernameProblemLanguageResultExecution timeMemory
887145Servant_of_the_LordSirni (COCI17_sirni)C++17
98 / 140
5123 ms611244 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O2") #define ll long long using namespace std; main() { ios_base::sync_with_stdio(false); cin.tie(0); ll x,y,z,a,b,c; cin>>x; set<ll>s; map<ll,ll>m; for(ll i=0;i<x;i++) { cin>>y; s.insert(y); m[y]=i; } vector<vector<ll>>v(10'000'000); for(ll i:s) { if(v[i-1].empty()) { for(ll j=i-1;j<10'000'000;j+=i) { v[j].push_back(i); } } } vector<ll>w(x,-1); z=x-1; function<ll(ll)>g=[&](ll a){return w[a]<0?a:w[a]=g(w[a]);}; function<bool(ll,ll)>u=[&](ll a,ll b) { a=g(m[a]),b=g(m[b]); if(a==b)return false; if(w[a]>w[b])swap(a,b); w[a]+=w[b]; w[b]=a; z--; return true; }; a=0; bitset<10'000'000>t; for(ll i=0;i<10'000'000;i++) { vector<ll>e; for(ll j:s) { for(ll k:v[j-i-1]) { if(u(j,k)) { a+=i; } } if(j-i-1==0||t[j-i-1])e.push_back(j); t[j-i-1]=1; } for(ll j:e)s.erase(j); if(s.empty()||z==0)break; } cout<<a<<'\n'; }

Compilation message (stderr)

sirni.cpp:7:5: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    7 |     main()
      |     ^~~~
sirni.cpp: In function 'int main()':
sirni.cpp:12:20: warning: unused variable 'b' [-Wunused-variable]
   12 |         ll x,y,z,a,b,c;
      |                    ^
sirni.cpp:12:22: warning: unused variable 'c' [-Wunused-variable]
   12 |         ll x,y,z,a,b,c;
      |                      ^
#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...