답안 #782047

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
782047 2023-07-13T15:05:48 Z Ahmed57 Sirni (COCI17_sirni) C++17
84 / 140
2016 ms 786432 KB
//#pragma GCC optimize("Ofast,O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>

using namespace std;
//DSU
int mn = 100001;
int pr[100001];
int gs[100001];

int findleader(int x){
    if(pr[x]==x){
        return x;
    }
    return pr[x] = findleader(pr[x]);
}
bool mergegroup(int x,int y){
    int led1 = findleader(x);
    int led2 = findleader(y);
    if(led1==led2)return 0;
    if(gs[led1]>gs[led2]){
        pr[led2]=led1;
        gs[led1]+=gs[led2];
    }else{
        pr[led1]=led2;
        gs[led2]+=gs[led1];
    }
    return 1;
}
vector<pair<long long,pair<int,int>>> ans;
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    set<int> s;
    int ma = 0;
    for(int i = 0;i<n;i++){
        int x;cin>>x;
        s.insert(x);
        ma = max(ma,x);
    }
    vector<int> arr;
    for(auto i:s)arr.push_back(i);
    n = arr.size();
    for(int i = 0;i<n;i++)pr[i] = i , gs[i] = 1;
    for(int i = 0;i<n;i++){
        int j = i+1;
        for(int e = arr[i];e<=ma;e+=arr[i]){
            while(j<n&&arr[j]<e)j++;
            if(j<n)ans.push_back({arr[j]%arr[i],{i,j}});
        }
    }
    sort(ans.begin(),ans.end());
    long long all = 0;
    for(int i = 0;i<ans.size();i++){
        if(mergegroup(ans[i].second.first,ans[i].second.second))all+=ans[i].first;
    }
    cout<<all<<"\n";
    return 0;
}

Compilation message

sirni.cpp: In function 'int main()':
sirni.cpp:55:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for(int i = 0;i<ans.size();i++){
      |                   ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 238 ms 66088 KB Output is correct
3 Correct 2 ms 976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Runtime error 746 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1286 ms 38824 KB Output is correct
2 Correct 1604 ms 71232 KB Output is correct
3 Correct 1068 ms 70636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 5316 KB Output is correct
2 Correct 341 ms 66648 KB Output is correct
3 Correct 944 ms 37796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1536 ms 71692 KB Output is correct
2 Correct 2016 ms 137116 KB Output is correct
3 Correct 1446 ms 38668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 252 ms 10636 KB Output is correct
2 Correct 1858 ms 136044 KB Output is correct
3 Correct 1116 ms 38196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1503 ms 39148 KB Output is correct
2 Runtime error 784 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1462 ms 39128 KB Output is correct
2 Runtime error 786 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 5664 KB Output is correct
2 Runtime error 1286 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -