답안 #568422

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
568422 2022-05-25T11:49:57 Z shahriarkhan Sirni (COCI17_sirni) C++14
126 / 140
3549 ms 786432 KB
#include<bits/stdc++.h>
using namespace std ;

const int MX = 1e7 + 5 ;

int nex[MX] ;

vector<pair<int,int> > val[MX] ;

struct dsu
{
    vector<int> sz , par ;
    void init(int n)
    {
        sz = vector<int> (n+2,0) ;
        par = vector<int> (n+2,0) ;
        for(int i = 1 ; i <= n ; ++i)
        {
            par[i] = i , sz[i] = 1 ;
        }
    }
    int find_root(int a)
    {
        if(par[a]==a) return a ;
        return par[a] = find_root(par[a]) ;
    }
    int union_edge(int u , int v)
    {
        int root_u = find_root(u) , root_v = find_root(v) ;
        if(root_u==root_v) return 0 ;
        if(sz[root_v]>sz[root_u]) swap(root_u,root_v) ;
        sz[root_u] += sz[root_v] ;
        par[root_v] = root_u ;
        return 1 ;
    }
};

int main()
{
    int n ;
    scanf("%d",&n) ;
    int p[n+2] = {0} ;
    long long ans = 0 ;
    for(int i = 1 ; i <= n ; ++i)
    {
        scanf("%d",&p[i]) ;
        nex[p[i]] = p[i] ;
    }
    for(int i = MX - 2 ; i >= 0 ; --i)
    {
        if(!nex[i]) nex[i] = nex[i+1] ;
    }
    dsu D ;
    D.init(MX) ;
    sort(p+1,p+n+1) ;
    for(int i = 1 ; i <= n ; ++i)
    {
        if(p[i-1]==p[i]) continue ;
        for(int j = p[i] ; j < MX ; j += p[i])
        {
            if(!nex[j+(j==p[i])]) continue ;
            int rem = nex[j+(j==p[i])]%p[i] ;
            val[rem].push_back({p[i],nex[j+(j==p[i])]}) ;
        }
    }
    for(int i = 0 ; i < MX ; ++i)
    {
        for(pair<int,int> &f : val[i])
        {
            int st = D.union_edge(f.first,f.second) ;
            if(st) ans += i ;
        }
    }
    printf("%lld\n",ans) ;
    return 0 ;
}

Compilation message

sirni.cpp: In function 'int main()':
sirni.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     scanf("%d",&n) ;
      |     ~~~~~^~~~~~~~~
sirni.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         scanf("%d",&p[i]) ;
      |         ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 229 ms 352588 KB Output is correct
2 Correct 317 ms 381956 KB Output is correct
3 Correct 256 ms 352988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 255 ms 352528 KB Output is correct
2 Correct 1591 ms 747332 KB Output is correct
3 Correct 216 ms 353376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 216 ms 352672 KB Output is correct
2 Correct 226 ms 352560 KB Output is correct
3 Correct 215 ms 352652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 417 ms 362376 KB Output is correct
2 Correct 750 ms 390888 KB Output is correct
3 Correct 450 ms 373472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 258 ms 354512 KB Output is correct
2 Correct 667 ms 375680 KB Output is correct
3 Correct 452 ms 362552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 555 ms 374544 KB Output is correct
2 Correct 930 ms 408464 KB Output is correct
3 Correct 414 ms 371640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 400 ms 356112 KB Output is correct
2 Correct 982 ms 409056 KB Output is correct
3 Correct 442 ms 373408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 354 ms 365848 KB Output is correct
2 Correct 2227 ms 710912 KB Output is correct
3 Correct 393 ms 368784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 408 ms 370180 KB Output is correct
2 Runtime error 2739 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 257 ms 354892 KB Output is correct
2 Correct 3549 ms 712424 KB Output is correct
3 Correct 444 ms 375516 KB Output is correct