Submission #978007

# Submission time Handle Problem Language Result Execution time Memory
978007 2024-05-08T16:06:35 Z alexdd popa (BOI18_popa) C++17
Compilation error
0 ms 0 KB
#include "popa.h"
#include<bits/stdc++.h>
using namespace std;

int _s[1005],_n;
int query(int a, int b, int c, int d)
{
    int gc1=_s[a],gc2=_s[c];
    for(int i=a;i<=b;i++)
        gc1 = __gcd(gc1,_s[i]);
    for(int i=c;i<=d;i++)
        gc2 = __gcd(gc2,_s[i]);
    if(gc1==gc2)
        return 1;
    return 0;
}

int tole[1005],tori[1005];
int calc(int le, int ri)
{
    if(le>ri)
        return -1;
    if(le==ri)
    {
        tole[le]=tori[le]=-1;
        return le;
    }
    for(int root=le;root<=ri;root++)
    {
        if(query(root,root,le,ri))
        {
            tole[root] = calc(le,root-1);
            tori[root] = calc(root+1,ri);
            return root;
        }
    }
}
int solve(int N, int* Left, int* Right)
{
    for(int i=0;i<N;i++)
        tole[i]=tori[i]=-1;
    int root = calc(0,N-1);
    for(int i=0;i<N;i++)
    {
        Left[i]=tole[i];
        Right[i]=tori[i];
    }
    return root;
}

int _left[1005],_right[1005];
signed main()
{
    cin>>_n;
    for(int i=0;i<_n;i++)
        cin>>_s[i];
    int root = solve(_n,_left,_right);
    cout<<root<<" the root\n";
    for(int i=0;i<_n;i++)
    {
        cout<<i<<"  "<<_left[i]<<" "<<_right[i]<<" left and right\n";
    }
    return 0;
}

Compilation message

popa.cpp: In function 'int calc(int, int)':
popa.cpp:37:1: warning: control reaches end of non-void function [-Wreturn-type]
   37 | }
      | ^
/usr/bin/ld: /tmp/cc4QCs8R.o: in function `query(int, int, int, int)':
popa.cpp:(.text+0x0): multiple definition of `query(int, int, int, int)'; /tmp/ccf9JvDS.o:grader.cpp:(.text+0x50): first defined here
/usr/bin/ld: /tmp/cc4QCs8R.o: in function `main':
popa.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccf9JvDS.o:grader.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status