답안 #782053

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
782053 2023-07-13T15:07:49 Z Ahmed57 Sirni (COCI17_sirni) C++17
98 / 140
5000 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);
    }
    assert(ma<=1e7);
    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}});
            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:57: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]
   57 |     for(int i = 0;i<ans.size();i++){
      |                   ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 27 ms 4548 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 42 ms 1416 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1283 ms 38852 KB Output is correct
2 Correct 1600 ms 71280 KB Output is correct
3 Correct 1000 ms 37788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 5316 KB Output is correct
2 Correct 328 ms 66544 KB Output is correct
3 Correct 982 ms 37808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1554 ms 71664 KB Output is correct
2 Correct 1951 ms 137200 KB Output is correct
3 Correct 1368 ms 38684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 201 ms 10672 KB Output is correct
2 Correct 1761 ms 136036 KB Output is correct
3 Correct 1076 ms 38152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1403 ms 39084 KB Output is correct
2 Execution timed out 5079 ms 532260 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1440 ms 39140 KB Output is correct
2 Runtime error 1860 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 5700 KB Output is correct
2 Runtime error 1773 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -