Submission #568417

# Submission time Handle Problem Language Result Execution time Memory
568417 2022-05-25T11:44:25 Z shahriarkhan Sirni (COCI17_sirni) C++14
126 / 140
3803 ms 786432 KB
#include<bits/stdc++.h>
using namespace std ;

const int MX = 1e7 + 5 ;

int nex[MX] , vis[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] ;
    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) ;
    for(int i = 1 ; i <= n ; ++i)
    {
        if(vis[p[i]]) continue ;
        vis[p[i]] = 1 ;
        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]) ;
      |         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 235 ms 356260 KB Output is correct
2 Correct 333 ms 387044 KB Output is correct
3 Correct 221 ms 356684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 273 ms 352608 KB Output is correct
2 Correct 1694 ms 779900 KB Output is correct
3 Correct 243 ms 357176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 250 ms 356532 KB Output is correct
2 Correct 233 ms 355032 KB Output is correct
3 Correct 237 ms 356612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 415 ms 366952 KB Output is correct
2 Correct 781 ms 394668 KB Output is correct
3 Correct 491 ms 380524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 255 ms 358424 KB Output is correct
2 Correct 669 ms 379988 KB Output is correct
3 Correct 467 ms 365324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 652 ms 378800 KB Output is correct
2 Correct 914 ms 413112 KB Output is correct
3 Correct 477 ms 376056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 397 ms 357124 KB Output is correct
2 Correct 1006 ms 415180 KB Output is correct
3 Correct 460 ms 377116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 393 ms 406376 KB Output is correct
2 Correct 2095 ms 775432 KB Output is correct
3 Correct 442 ms 409364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 436 ms 410188 KB Output is correct
2 Runtime error 2604 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 289 ms 389148 KB Output is correct
2 Correct 3803 ms 769156 KB Output is correct
3 Correct 510 ms 379388 KB Output is correct