# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
949309 | 2024-03-19T05:39:35 Z | vjudge1 | Sirni (COCI17_sirni) | C++17 | 4377 ms | 757420 KB |
#include <bits/stdc++.h> using namespace std; #define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fr first #define sc second #define endl "\n" #define ll long long //#define int long long void fopn(string name){ freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } const ll INF=1e18,mod=1e9,N=1e7+5; int n; int ans=0,par[N]; int f(int x){ if(par[x]==x) return x; return par[x]=f(par[x]); } vector<pair<int,int>> g[N]; void add(int a, int b, int c){ a=f(a);b=f(b); if(a==b) return; ans+=c; if(rand()%2) swap(a,b); par[a]=b; } void solve(){ int n;cin>>n; vector<int> p(n); for(int i=0;i<n;i++){ cin>>p[i]; } for(int i=1;i<=1e7;i++) par[i]=i; sort(all(p)); for(int i=0;i<n;i++){ int j=i+1; for(int cur=p[i];cur<=1e7;cur+=p[i]){ while(j<n && p[j]<cur) j++; if(j<n) g[p[j]%p[i]].pb({i,j}); j++; } } for(int i=0;i<=1e7;i++){ for(auto it: g[i]) add(it.fr,it.sc,i); } cout<<ans<<endl; } main(){ ios; int T=1; //cin>>T; for(int i=1;i<=T;i++){ //cout<<"Case #"<<i<<": "; solve(); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 160 ms | 274564 KB | Output is correct |
2 | Correct | 106 ms | 277592 KB | Output is correct |
3 | Correct | 111 ms | 274724 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 102 ms | 274476 KB | Output is correct |
2 | Correct | 171 ms | 275284 KB | Output is correct |
3 | Correct | 99 ms | 274512 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 94 ms | 274340 KB | Output is correct |
2 | Correct | 96 ms | 274412 KB | Output is correct |
3 | Correct | 101 ms | 274524 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3238 ms | 284952 KB | Output is correct |
2 | Correct | 2961 ms | 324184 KB | Output is correct |
3 | Correct | 3405 ms | 296464 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 166 ms | 276052 KB | Output is correct |
2 | Correct | 3982 ms | 565372 KB | Output is correct |
3 | Correct | 2925 ms | 287544 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3529 ms | 298940 KB | Output is correct |
2 | Correct | 3448 ms | 355188 KB | Output is correct |
3 | Correct | 3293 ms | 289560 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 597 ms | 278860 KB | Output is correct |
2 | Correct | 3490 ms | 345484 KB | Output is correct |
3 | Correct | 3360 ms | 293716 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2128 ms | 287656 KB | Output is correct |
2 | Correct | 2811 ms | 597860 KB | Output is correct |
3 | Correct | 2248 ms | 290588 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2130 ms | 287420 KB | Output is correct |
2 | Correct | 4048 ms | 710964 KB | Output is correct |
3 | Correct | 2270 ms | 298908 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 187 ms | 276572 KB | Output is correct |
2 | Correct | 4377 ms | 757420 KB | Output is correct |
3 | Correct | 3305 ms | 298444 KB | Output is correct |