답안 #1108162

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1108162 2024-11-03T05:39:24 Z KDM_Dvali 나일강 (IOI24_nile) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<ll> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E) {
    int n = W.size();
    int q = E.size();
    vector<ll> R(q, 0);
    ll sb = 0;

    // Calculate sum of B
    for (int i = 0; i < n; i++) {
        sb += B[i];
    }

    for (int i = 0; i < q; i++) {
        ll d = E[i];
        long long pmin = LLONG_MAX;

        // Check if third subtask conditions are met
        bool third_subtask = (q <= 5 && all_of(A.begin(), A.end(), [](int a) { return a == 2; }) && all_of(B.begin(), B.end(), [](int b) { return b == 1; }));

        if (third_subtask) {
            // If third subtask, apply optimized calculation
            R[i] = sb + n;  // Since A[i] - B[i] = 1 for all i, and we need to add sum(B) + min(A[i] - B[i])
            continue;
        }

        if (n % 2 == 0) {
            // If n is even, set result to sum of B values
            R[i] = sb;
            continue;
        } else {
            // Otherwise, find minimum (A[j] - B[j]) under the given conditions
            for (int j = 0; j < n; j++) {
                if (j % 2 == 0) {
                    pmin = min(pmin, (long long)A[j] - B[j]);
                }
                if (j > 0 && j < n - 1) {
                    if (W[j + 1] - W[j - 1] <= d) {
                        pmin = min(pmin, (long long)A[j] - B[j]);
                    }
                }
            }
        }
        R[i] = pmin + sb;
    }

    return R;
}

int main() {
    int n, q;
    cin >> n >> q;
    
    vector<int> W(n), A(n, 2), B(n, 1), E(q);
    
    // Input values for W, A, B arrays
    for (int i = 0; i < n; i++) {
        W[i] = i + 1;  
        cin >> A[i] >> B[i];
    }
    
    // Input values for E array
    for (int i = 0; i < q; i++) {
        cin >> E[i];
    }
    
    // Get result for each query
    vector<ll> result = calculate_costs(W, A, B, E);
  
    // Print the results
    for (size_t i = 0; i < result.size(); i++) {
        cout << result[i] << " ";
    }
    cout << endl;
    
    return 0;
}

Compilation message

/usr/bin/ld: /tmp/ccsWq3XU.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccYb8TLR.o:nile.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status