답안 #782040

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
782040 2023-07-13T15:00:52 Z Ahmed57 Sirni (COCI17_sirni) C++17
84 / 140
2711 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;
}
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;
    vector<pair<int,pair<int,int>>> ans;
    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<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 2 ms 468 KB Output is correct
2 Correct 230 ms 49780 KB Output is correct
3 Correct 3 ms 892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Runtime error 705 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2037 ms 31508 KB Output is correct
2 Correct 2361 ms 55648 KB Output is correct
3 Correct 1649 ms 55088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 4492 KB Output is correct
2 Correct 340 ms 50724 KB Output is correct
3 Correct 1460 ms 30536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2278 ms 56152 KB Output is correct
2 Correct 2711 ms 105156 KB Output is correct
3 Correct 2043 ms 31408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 320 ms 8884 KB Output is correct
2 Correct 2530 ms 104068 KB Output is correct
3 Correct 1697 ms 30780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2195 ms 31912 KB Output is correct
2 Runtime error 777 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2288 ms 31908 KB Output is correct
2 Runtime error 775 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 129 ms 4812 KB Output is correct
2 Runtime error 1518 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -