답안 #1061573

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1061573 2024-08-16T10:59:15 Z dimasnbayu Sirni (COCI17_sirni) C++14
0 / 140
380 ms 67892 KB
#include<bits/stdc++.h>
using namespace std;
const int sz=1e5+5;
int par[sz],nx[10000005];
vector<int> arr;
vector<pair<int,pair<int,int>>> v;
int find(int x){
    if(par[x]==x) return x;
    else return par[x]=find(par[x]);
}
void merge(int x, int y){
    x=find(x),y=find(y);
    par[x]=y;
}
bool check(int x, int y){
    return find(x)==find(y);
}
int main(){
    int n; cin>>n;
    for(int i=1;i<=n;i++){
        int a; cin>>a;
        arr.push_back(a);
    }
    arr.erase(unique(arr.begin(),arr.end()), arr.end());
    sort(arr.begin(),arr.end());
    for(int i=0;i<arr.size();i++) par[i]=i;
    int now=0;
    for(int i=0;i<=arr.back();i++){
        while(now<arr.size() && arr[now]<=i) now++;
        nx[i]=now;
    }
    for(int i=0;i<arr.size();i++){
        // cout<<arr[i]<<" ";
        for(int j=arr[i];j<=arr.back();j+=arr[i]){
            if(nx[j]<arr.size()) v.push_back({arr[nx[j]]%arr[i],{i,nx[j]}});
        }
    }
    // cout<<endl;
    sort(v.begin(),v.end());
    int ans=0;
    for(int i=0;i<v.size();i++){
        // cout<<v[i].first<<" "<<v[i].second.first<<" "<<v[i].second.second<<endl;
        if(!check(v[i].second.first,v[i].second.second)){
            ans+=v[i].first;
            merge(v[i].second.first,v[i].second.second);
        }
    }
    cout<<ans;
}

Compilation message

sirni.cpp: In function 'int main()':
sirni.cpp:26:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int i=0;i<arr.size();i++) par[i]=i;
      |                 ~^~~~~~~~~~~
sirni.cpp:29:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         while(now<arr.size() && arr[now]<=i) now++;
      |               ~~~^~~~~~~~~~~
sirni.cpp:32:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for(int i=0;i<arr.size();i++){
      |                 ~^~~~~~~~~~~
sirni.cpp:35:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |             if(nx[j]<arr.size()) v.push_back({arr[nx[j]]%arr[i],{i,nx[j]}});
      |                ~~~~~^~~~~~~~~~~
sirni.cpp:41:18: 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]
   41 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 39516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 39740 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 171 ms 34524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 27 ms 11260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 380 ms 58160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 59 ms 13384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 217 ms 66140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 241 ms 67892 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 44240 KB Output isn't correct
2 Halted 0 ms 0 KB -