Submission #1250220

#TimeUsernameProblemLanguageResultExecution timeMemory
1250220ezzzayTriple Peaks (IOI25_triples)C++17
Compilation error
0 ms0 KiB
// triples.cpp
#include "triples.h"
#include <vector>
using namespace std;

// Part I: O(N) scan by anchoring on each index
long long count_triples(const vector<int>& H) {
    int N = H.size();
    long long ans = 0;
    // Case A: H[i] = d(i,j), H[j] = d(j,k)
    for(int i = 0; i < N; i++){
        int j = i + H[i];
        if(j < N){
            int k = j + H[j];
            if(k < N && H[k] == H[i] + H[j])
                ans++;
        }
    }
    // Case B: H[i] = d(i,j), H[k] = d(i,k)
    for(int i = 0; i < N; i++){
        int k = i + H[i];
        if(k < N){
            int j = k - H[k];
            if(j > i && j < N && H[j] == H[i] + H[k])
                ans++;
        }
    }
    // Case C: H[j] = d(i,j) = d(j,k)
    for(int j = 0; j < N; j++){
        int i = j - H[j];
        int k = j + H[j];
        if(i >= 0 && k < N && H[i] + H[k] == H[j])
            ans++;
    }
    return ans;
}

// Part II: all-1s gives (N-2) triples in N peaks
vector<int> construct_range(int M, int K) {
    int N;
    if(M >= K + 2) {
        // can hit exactly K triples → full credit
        N = K + 2;
    } else if(M >= 3) {
        // use all M peaks → M-2 triples
        N = M;
    } else {
        // too small for any triple, just output M ones
        N = M;
    }
    return vector<int>(N, 1);
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccHJ45d6.o: in function `main':
grader.cpp:(.text.startup+0x34b): undefined reference to `count_triples(std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status