Submission #1095521

# Submission time Handle Problem Language Result Execution time Memory
1095521 2024-10-02T13:17:44 Z 0pt1mus23 Sirni (COCI17_sirni) C++14
0 / 140
694 ms 499924 KB
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ins insert
#define pb push_back
#define putr(x) cout<<x<<endl;return;
#define all(x) x.begin(),x.end()
#define _ << " " <<  
const int   mod = 1e9+7 ,
            sze= 1e7*2 +23 ,
            inf = INT_MAX ,
            L = 31 ;
// credit : aykhn
int parent[sze];
int sz[sze];
int root(int node){
    if(parent[node]==node){
        return node;
    }
    return parent[node]=root(parent[node]);
}
int unite(int a,int b){
    int x = root(a);
    int y = root(b);
    if(x==y){
        return 0;
    }
    if(sz[y]>sz[x]){
        swap(y,x);
    }
    parent[y]=x;
    sz[x]+=sz[y];
    return 1;
}

vector<pair<int,int>> event[sze];
void opt1z(){
    int n;
    cin>>n;
    for(int i=0;i<=(int)n+23;i++){
        sz[i]=1;
        parent[i]=i;
    }
    int ans=0;

    vector<int> arr(n);
    set<pair<int,int>> lst;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        lst.ins({arr[i],i});
    }
    sort(all(arr));
    
    vector<int> yuxari;
    int mx = arr.back()+23;
    

    for(auto v:lst){
        int c =v.first;
        int i = v.second;
        while(c<=mx){
            auto it = lst.end();
            if(c==v.first){
                it = lst.upper_bound({c,inf});
            }  
            else{
                it = lst.lower_bound({c,-1});
            }
            if(it==lst.end()){
                break;
            }
            pair<int,int> it2 = *it;
            // cout<<v _ " ," _  c _ *it % v <<endl;
            event[ (it2.first) % v.first ].pb({i,it2.second});
            c = ((it2.first) / v.first) * v.first;
            c+=v.first;
        }
    }
    for(int i =0;i<=mx;i++){
        for(auto v:event[i]){
            // cout<<i _ v.first _ "=> " _ v.second<<endl;
            if(unite(v.first,v.second)){
                ans+=i;
            }
        }
    }


    putr(ans);
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int tt = 1;
    // cin>>tt;
    while(tt--){
        opt1z();
    }
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 206 ms 470096 KB Output is correct
2 Incorrect 220 ms 473056 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 186 ms 470096 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 207 ms 470096 KB Output is correct
2 Incorrect 196 ms 470140 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 423 ms 485372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 214 ms 472524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 694 ms 499924 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 255 ms 475576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 428 ms 487860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 405 ms 487588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 219 ms 473416 KB Output isn't correct
2 Halted 0 ms 0 KB -