Submission #1061579

# Submission time Handle Problem Language Result Execution time Memory
1061579 2024-08-16T11:01:30 Z dimasnbayu Sirni (COCI17_sirni) C++14
0 / 140
423 ms 131056 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
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);
}
signed 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() && i<nx[j]) 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:27:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i=0;i<arr.size();i++) par[i]=i;
      |                 ~^~~~~~~~~~~
sirni.cpp:30:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         while(now<arr.size() && arr[now]<=i) now++;
      |               ~~~^~~~~~~~~~~
sirni.cpp:33:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for(int i=0;i<arr.size();i++){
      |                 ~^~~~~~~~~~~
sirni.cpp:36:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |             if(nx[j]<arr.size() && i<nx[j]) v.push_back({arr[nx[j]]%arr[i],{i,nx[j]}});
      |                ~~~~~^~~~~~~~~~~
sirni.cpp:42:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 78820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 78936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 203 ms 60732 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 16588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 423 ms 109464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 17476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 245 ms 130208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 260 ms 131056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 87224 KB Output isn't correct
2 Halted 0 ms 0 KB -