Submission #985450

# Submission time Handle Problem Language Result Execution time Memory
985450 2024-05-17T21:20:44 Z islam998 Wall (IOI14_wall) C++17
Compilation error
0 ms 0 KB
#include <iostream>
#include <vector>
#include <algorithm>

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> a(N), b(N);

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

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

    // Function to calculate water collected given heights
    auto calculateWater = [](const vector<int>& heights) {
        int N = heights.size();
        vector<int> leftMax(N), rightMax(N);
        leftMax[0] = heights[0];
        for (int i = 1; i < N; ++i) {
            leftMax[i] = max(leftMax[i - 1], heights[i]);
        }
        rightMax[N - 1] = heights[N - 1];
        for (int i = N - 2; i >= 0; --i) {
            rightMax[i] = max(rightMax[i + 1], heights[i]);
        }
        ll totalWater = 0;
        for (int i = 0; i < N; ++i) {
            totalWater += min(leftMax[i], rightMax[i]) - heights[i];
        }
        return totalWater;
    };

    // Calculate water collected for all possible combinations
    ll totalSum = 0;
    int totalCombinations = 1 << N; // 2^N combinations

    for (int mask = 0; mask < totalCombinations; ++mask) {
        vector<int> heights(N);
        for (int i = 0; i < N; ++i) {
            if (mask & (1 << i)) {
                heights[i] = b[i];
            } else {
                heights[i] = a[i];
            }
        }
        totalSum = (totalSum + calculateWater(heights)) % MOD;
    }

    cout << totalSum << endl;

    return 0;
}

Compilation message

/usr/bin/ld: /tmp/ccunzEAW.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc6oCLUU.o:wall.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccunzEAW.o: in function `main':
grader.cpp:(.text.startup+0x133): undefined reference to `buildWall(int, int, int*, int*, int*, int*, int*)'
collect2: error: ld returned 1 exit status