제출 #1148802

#제출 시각아이디문제언어결과실행 시간메모리
1148802erering가장 긴 여행 (IOI23_longesttrip)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#include "longesttrip.h"
vector<int> longest_trip(int N, int D)
{
    srand(time(NULL));
    vector<int> ans;
    for(int i=0;i<34;i++) {
        vector<int> a;
        for(int j=0;j<N;j++)a.pb(j);
        vector<int> vec;
        int x=rand()%N;
        vec.pb(a[x]);
        a.erase(a.begin()+x);
        for(int j=1;j<N;j++){
            vector<int> rem=a;
            while(rem.size()>0){
                int x=rand()%rem.size();
                if(are_connected({rem[x]},{vec[j-1]})){
                    vec.pb(rem[x]);
                    int idx;
                    for(int k=0;k<a.size();k++){
                        if(a[k]==rem[x])idx=k;
                    }
                    a.erase(a.begin()+idx);
                    break;
                }
                rem.erase(rem.begin()+x);
            }
            if(vec.size()==j)break;
        }
        if(vec.size()>ans.size())ans=vec;
    }
  //  for(auto i:ans)cout<<i<<" ";
  //  cout<<endl;
    return ans;
}

#include <cassert>
#include <cstdio>
#include <string>
#include <vector>

static inline constexpr int maxNumberOfCalls = 32640;
static inline constexpr int maxTotalNumberOfCalls = 150000;
static inline constexpr int maxTotalNumberOfLandmarksInCalls = 1500000;
static int call_counter = 0;
static int total_call_counter = 0;
static int landmark_counter = 0;

static int C, N, D;
static std::vector<std::vector<int>> U;
static std::vector<bool> present;

static inline void protocol_violation(std::string message)
{
    printf("Protocol Violation: %s\n", message.c_str());
    exit(0);
}

bool are_connected(std::vector<int> A, std::vector<int> B)
{
    ++call_counter;
    ++total_call_counter;
    if (call_counter > maxNumberOfCalls || total_call_counter > maxTotalNumberOfCalls)
    {
        protocol_violation("too many calls");
    }

    int nA = A.size(), nB = B.size();
    landmark_counter += nA + nB;
    if (landmark_counter > maxTotalNumberOfLandmarksInCalls)
    {
        protocol_violation("too many elements");
    }

    if (nA == 0 || nB == 0)
    {
        protocol_violation("invalid array");
    }
    for (int i = 0; i < nA; ++i)
    {
        if (A[i] < 0 || N <= A[i])
        {
            protocol_violation("invalid array");
        }
        if (present[A[i]])
        {
            protocol_violation("invalid array");
        }
        present[A[i]] = true;
    }
    for (int i = 0; i < nA; ++i)
    {
        present[A[i]] = false;
    }
    for (int i = 0; i < nB; ++i)
    {
        if (B[i] < 0 || N <= B[i])
        {
            protocol_violation("invalidd array");
        }
        if (present[B[i]])
        {
            protocol_violation("invalid array");
        }
        present[B[i]] = true;
    }
    for (int i = 0; i < nB; ++i)
    {
        present[B[i]] = false;
    }

    for (int i = 0; i < nA; ++i)
    {
        for (int j = 0; j < nB; ++j)
        {
            if (A[i] == B[j])
            {
                protocol_violation("non-disjoint arrays");
            }
        }
    }

    for (int i = 0; i < nA; ++i)
    {
        for (int j = 0; j < nB; ++j)
        {
            if (U[std::max(A[i], B[j])][std::min(A[i], B[j])] == 1)
            {
                return true;
            }
        }
    }

    return false;
}

int main()
{
    assert(1 == scanf("%d", &C));
    int maximumCalls = 0;
    for (int c = 0; c < C; ++c)
    {
        call_counter = 0;
        assert(2 == scanf("%d %d", &N, &D));

        present.assign(N, false);
        U.resize(N);
        for (int i = 1; i < N; ++i)
        {
            U[i].resize(i);
            for (int j = 0; j < i; ++j)
            {
                assert(1 == scanf("%d", &U[i][j]));
            }
        }

        for (int i = 2; i < N; ++i)
        {
            for (int j = 1; j < i; ++j)
            {
                for (int k = 0; k < j; ++k)
                {
                    if (U[i][j] + U[i][k] + U[j][k] < D)
                    {
                        printf("Insufficient Density\n");
                        exit(0);
                    }
                }
            }
        }

        std::vector<int> t = longest_trip(N, D);
        int l = t.size();
        printf("%d\n", l);
        for (int i = 0; i < l; ++i)
        {
            printf(i == 0 ? "%d" : " %d", t[i]);
        }
        printf("\n");
        printf("%d\n", call_counter);

        maximumCalls = std::max(maximumCalls, call_counter);
        call_counter = 0;
    }
    printf("%d\n", maximumCalls);

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

/usr/bin/ld: /tmp/ccp8SXS0.o: in function `are_connected(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)':
stub.cpp:(.text+0xd0): multiple definition of `are_connected(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'; /tmp/ccIHdAnp.o:longesttrip.cpp:(.text+0x30): first defined here
/usr/bin/ld: /tmp/ccp8SXS0.o: in function `main':
stub.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccIHdAnp.o:longesttrip.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status