Submission #147714

# Submission time Handle Problem Language Result Execution time Memory
147714 2019-08-30T13:18:16 Z Ruxandra985 Sirni (COCI17_sirni) C++14
Compilation error
0 ms 0 KB
/// alta mini bulaneala :)
#include <cstdio>
#include <algorithm>
#define DIM 100010
using namespace std;
int v[DIM];
vector <pair <int,int> > m[10000000];
int tt[DIM];
int biggest[10000010];
int fth ( int x ){
    int aux;
    int init = x;
    while (tt[x]>=0){
        x = tt[x];
    }
    while (tt[init]>=0){
        aux = tt[init];
        tt[init] = x;
        init = aux;
    }

    return x;
}
int main()
{
   // freopen ("a.in" , "r" , stdin);
   // freopen ("a.out" , "w" , stdout);
    int n,i,elem,p,mch,j,x,y,tx,ty;
    long long sol=0;
    scanf ("%d",&n);
    for (i=1;i<=n;i++){
        scanf ("%d",&v[i]);
    }
    sort (v+1,v+n+1);
    elem = 0;
    for (i=1;i<=n;i++){
        if (i==1 || v[i]!=v[i-1])
            v[++elem] = v[i];
    }
    n = elem;
    p=n;
    for (i=v[n];i;i--){
        if (p && v[p] == i){
            biggest[i] = p;
            p--;
        }
        else biggest[i] = biggest[i+1];
    }
    mch=0;
    for (i=1;i<=n;i++){
        if (i!=n && v[i+1]/v[i] == 1){
            m[v[i+1] - v[i]].push_back(make_pair(i,i+1));
        }
        for (j=2*v[i];j<=v[n];j+=v[i]){
            /// cea mai mica val mai mare decat j
            x = biggest[j];
            if (j/v[i] == v[x]/v[i]){ /// add muchie
                m[v[x] - j].push_back(make_pair(i,x));
            }
        }
    }
    for (i=1;i<=n;i++)
        tt[i] = -1;
    int pus = 0;
    for (i=0;i<10000000 && pus!=n-1 ; i++){
        for (j=0;j<m[i].size();j++){
            x = m[i][j].first;
            y = m[i][j].second;
            tx = fth(x);
            ty = fth(y);
            if (tx!=ty){
                sol+=i;
                pus++;
                //printf ("%d ",m[i].first);
                if (tt[tx] < tt[ty]){
                    tt[tx]+=tt[ty];
                    tt[ty] = tx;
                }
                else {
                    tt[ty]+=tt[tx];
                    tt[tx] = ty;
                }
            }
        }
    }
    printf ("%lld",sol);
    return 0;
}

Compilation message

sirni.cpp:7:1: error: 'vector' does not name a type; did you mean 'qecvt_r'?
 vector <pair <int,int> > m[10000000];
 ^~~~~~
 qecvt_r
sirni.cpp: In function 'int main()':
sirni.cpp:52:13: error: 'm' was not declared in this scope
             m[v[i+1] - v[i]].push_back(make_pair(i,i+1));
             ^
sirni.cpp:58:17: error: 'm' was not declared in this scope
                 m[v[x] - j].push_back(make_pair(i,x));
                 ^
sirni.cpp:66:20: error: 'm' was not declared in this scope
         for (j=0;j<m[i].size();j++){
                    ^
sirni.cpp:30:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%d",&n);
     ~~~~~~^~~~~~~~~
sirni.cpp:32:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%d",&v[i]);
         ~~~~~~^~~~~~~~~~~~