제출 #1287040

#제출 시각아이디문제언어결과실행 시간메모리
1287040ecen303개의 봉우리 (IOI25_triples)C++20
컴파일 에러
0 ms0 KiB
//TEsting AI COde
#include <iostream>
#include <vector>
#include <algorithm>

// Function to count the mythical triples
long long count_triples(std::vector<int>& H) {
    int N = H.size();
    long long mythical_triples = 0;

    // Iterate over all triplets (i, j, k)
    for (int i = 0; i < N - 2; ++i) {
        for (int j = i + 1; j < N - 1; ++j) {
            for (int k = j + 1; k < N; ++k) {
                // Calculate pairwise distances
                std::vector<int> distances = { j - i, k - i, k - j };
                std::vector<int> heights = { H[i], H[j], H[k] };
                
                // Sort both distances and heights
                std::sort(distances.begin(), distances.end());
                std::sort(heights.begin(), heights.end());
                
                // If they match, it's a mythical triple
                if (distances == heights) {
                    mythical_triples++;
                }
            }
        }
    }

    return mythical_triples;
}

// Function to construct a mountain range that produces at least K mythical triples
std::vector<int> construct_range(int M, int K) {
    // Try to create a range with many mythical triples. We use a pattern that repeats
    // numbers in such a way to increase the likelihood of matching distances.
    std::vector<int> H;

    // Strategy: Create a simple increasing-decreasing pattern
    for (int i = 1; i <= M - 2; ++i) {
        H.push_back(i);
    }
    H.push_back(M - 1);  // The last peak at height M-1

    // For Part II, we might not know the exact number of mythical triples, but we try
    // to generate a range that has a reasonable number of them.
    return H;
}

int main() {
    int part;
    std::cin >> part;

    if (part == 1) {
        // Part I: Count mythical triples
        int N;
        std::cin >> N;
        std::vector<int> H(N);

        for (int i = 0; i < N; ++i) {
            std::cin >> H[i];
        }

        long long result = count_triples(H);
        std::cout << result << std::endl;

    } else if (part == 2) {
        // Part II: Construct a mountain range with at least K mythical triples
        int M, K;
        std::cin >> M >> K;

        std::vector<int> range = construct_range(M, K);

        std::cout << range.size() << std::endl;
        for (int i = 0; i < range.size(); ++i) {
            std::cout << range[i] << " ";
        }
        std::cout << std::endl;
    }

    return 0;
}

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

/usr/bin/ld: /tmp/ccA1Ngnm.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccLrczot.o:triples.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccA1Ngnm.o: in function `main':
grader.cpp:(.text.startup+0x367): undefined reference to `count_triples(std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status