Submission #949273

# Submission time Handle Problem Language Result Execution time Memory
949273 2024-03-19T04:45:50 Z vjudge1 Sirni (COCI17_sirni) C++17
0 / 140
35 ms 15056 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=1e7+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();
                if(v[low]%i<v[1])s.ins({v[low]%v[i],{i,low}});
            }
        }else{
            for(j=i+1;j<=n;j++){
                if(v[low]%i<v[1])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;
      |          ^~~
sirni.cpp:81:25: warning: 'low' may be used uninitialized in this function [-Wmaybe-uninitialized]
   81 |                 if(v[low]%i<v[1])s.ins({v[j]%v[i],{i,j}});
      |                         ^
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 34 ms 14468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 2908 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 34 ms 14544 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 5844 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 34 ms 15056 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 35 ms 15048 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 3564 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -