# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
949266 |
2024-03-19T04:40:26 Z |
vjudge1 |
Sirni (COCI17_sirni) |
C++17 |
|
5000 ms |
337156 KB |
#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
#define pll vector<pair<ll,ll>>
using namespace std;/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>*/
template<class S,class T>
bool chmin(S &a,const T &b) {
return a>b?(a=b)==b:false;
}
template<class S,class T>
bool chmax(S &a,const T &b) {
return a<b?(a=b)==b:false;
}
void start(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const ll N=1e5+5;
const ll M=1e6+5;
ll siz[N],p[N];
vll v(1);
ll anc(ll a){
return (a==p[a] ? a : p[a]=anc(p[a]));
}
bool uni(ll a,ll b){
a=anc(a);
b=anc(b);
if(a==b) return false;
if(siz[a]>siz[b])swap(a,b);
siz[b]+=siz[a];
p[a]=b;
return true;
}
void solve(){
ll i,j;
ll n,sum=0;
cin>>n;
ll a;
set<ll> st;
for(i=0;i<n;i++){
cin>>a;
p[i+1]=i+1;
siz[i+1]=1;
st.ins(a);
}
n=st.sz;
for(auto i : st) v.pb(i);
set<pair<ll,pair<ll,ll>>> s;
ll low;
for(i=1;i<=n;i++){
if(M/v[i]*15<n-i){
for(j=v[i]*2;j<=M;j+=v[i]){
if(j>v.bc) break;
low=lb(all(v),j)-v.begin();
s.ins({v[low]%v[i],{i,low}});
}
}else{
for(j=i+1;j<=n;j++){
s.ins({v[j]%v[i],{i,j}});
}
}
}
ll c=n-1;
ll ans=0;
while(c){
ll a=s.begin()->sc.fr,b=s.begin()->sc.sc;
s.erase(s.begin());
if(b!=n && v[b]/v[a]==v[b+1]/v[a])s.ins({v[b+1]%v[a],{a,b+1}});
if(uni(a,b)){c--;ans+=v[b]%v[a];};
}
cout<<ans<<endl;
}
signed main(){
start();
ll t=1;
//cin>>t;
while(t--) solve();
return 0;
}
/*
*/
Compilation message
sirni.cpp: In function 'void solve()':
sirni.cpp:58:10: warning: unused variable 'sum' [-Wunused-variable]
58 | ll n,sum=0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5022 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
183 ms |
28088 KB |
Output is correct |
2 |
Correct |
76 ms |
15184 KB |
Output is correct |
3 |
Incorrect |
2 ms |
860 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5069 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1268 ms |
128196 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
130 ms |
19284 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3444 ms |
337156 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1475 ms |
173856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
168 ms |
24552 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
120 ms |
24296 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5055 ms |
2520 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |