제출 #1343370

#제출 시각아이디문제언어결과실행 시간메모리
1343370maxiedBikeparking (EGOI24_bikeparking)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<int> x(n), y(n);
    for (int i = 0; i < n; i++){
        cin >> x[i];
    }
    for (int i = 0; i < n; i++){
        cin >> y[i];
    }
    if (n <= 100 && *max_element(x.begin(), x.end()) <= 100 && *max_element(y.begin(), y.end()) <= 100){
    int sum = 0;
    for (int i = 0; i < n; i++){
        sum += y[i];
    }
    int ans = -INT_MAX;
    for (int bully = 0; bully <= sum; bully++){
        int cur = 0;
        // assign the bullied to the worst position
        // assign the rest to the best position
        int cbully = bully;
        int rest = sum - bully;
        vector<int> tx = x;
        vector<int> ty = y;
        int l = 0;
        int r = n - 1;
        int tkn = 0;
        int i = 0;
        // these people have tier i
        // l/r is the thing they are given
        // tx is the free spots
        // ty is the people taking
        while (i < n){
            if (!cbully){
                if (!rest){
                    break;
                }
                int take = min(tx[l], min(rest, ty[i]));
                //cout << i << "take rest " << take << '\n';
                if (i < l){
                    cur -= take;
                }
                else if (i > l){
                    cur += take;
                }
                tx[l] -= take;
                rest -= take;
                ty[i] -= take;
                if (tx[l] == 0){
                    l++;
                }
                if (ty[i] == 0){
                    i++;
                }
                continue;
            }
            int take = min(tx[r], min(cbully, ty[i]));
            //cout << i << "take bully " << take << '\n';
            if (i < r){
                cur -= take;
            }
            else if (i > r){
                cur += take;
            }
            tx[r] -= take;
            cbully -= take;
            ty[i] -= take;
            if (tx[r] == 0){
                r--;
            }
            if (ty[i] == 0){
                i++;
            }
        }
        //cout << bully << ' ' << cur << endl;
        ans = max(ans, cur);
    }
    cout << ans << '\n';
}
        return 0;
    }
    int sum = 0;
    for (int i = 0; i < n; i++){
        sum += y[i];
    }
    int ans = -INT_MAX;
    // it will decrease, then increase.
    auto f = [&](int bully) -> int{
        int cur = 0;
        // assign the bullied to the worst position
        // assign the rest to the best position
        int cbully = bully;
        int rest = sum - bully;
        vector<int> tx = x;
        vector<int> ty = y;
        int l = 0;
        int r = n - 1;
        int tkn = 0;
        int i = 0;
        // these people have tier i
        // l/r is the thing they are given
        // tx is the free spots
        // ty is the people taking
        while (i < n){
            if (!cbully){
                if (!rest){
                    break;
                }
                int take = min(tx[l], min(rest, ty[i]));
                //cout << i << "take rest " << take << '\n';
                if (i < l){
                    cur -= take;
                }
                else if (i > l){
                    cur += take;
                }
                tx[l] -= take;
                rest -= take;
                ty[i] -= take;
                if (tx[l] == 0){
                    l++;
                }
                if (ty[i] == 0){
                    i++;
                }
                continue;
            }
            int take = min(tx[r], min(cbully, ty[i]));
            //cout << i << "take bully " << take << '\n';
            if (i < r){
                cur -= take;
            }
            else if (i > r){
                cur += take;
            }
            tx[r] -= take;
            cbully -= take;
            ty[i] -= take;
            if (tx[r] == 0){
                r--;
            }
            if (ty[i] == 0){
                i++;
            }
        }
        return cur;

    };
    int lowest = f(sum);
    int lo = 0, hi = sum - 1;
    // first point where its not lowest
    // TTTFFF
    while (lo < hi){
        int mid = (lo + hi + 1) >> 1;
        if (f(mid) == lowest){
            hi = mid - 1;
        }
        else{
            lo = mid;
        }
    }
    hi = lo;
    lo = 0;
    // find first point where f(x) > f(x + 1)
    // FFFFFFTTTTT
    while (lo < hi){
        int mid = (lo + hi) >> 1;
        if (f(mid) >= f(mid + 1)){
            hi = mid;
        }
        else{
            lo = mid + 1;
        }
    }
    cout << f(lo) << '\n';
}

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

Main.cpp:90:5: error: expected unqualified-id before 'for'
   90 |     for (int i = 0; i < n; i++){
      |     ^~~
Main.cpp:90:25: error: 'n' was not declared in this scope; did you mean 'yn'?
   90 |     for (int i = 0; i < n; i++){
      |                         ^
      |                         yn
Main.cpp:90:25: error: 'n' was not declared in this scope; did you mean 'yn'?
   90 |     for (int i = 0; i < n; i++){
      |                         ^
      |                         yn
Main.cpp:90:25: error: 'n' was not declared in this scope; did you mean 'yn'?
   90 |     for (int i = 0; i < n; i++){
      |                         ^
      |                         yn
Main.cpp:90:25: error: 'n' was not declared in this scope; did you mean 'yn'?
   90 |     for (int i = 0; i < n; i++){
      |                         ^
      |                         yn
Main.cpp:90:25: error: 'n' was not declared in this scope; did you mean 'yn'?
   90 |     for (int i = 0; i < n; i++){
      |                         ^
      |                         yn
Main.cpp:90:25: error: 'n' was not declared in this scope; did you mean 'yn'?
   90 |     for (int i = 0; i < n; i++){
      |                         ^
      |                         yn
Main.cpp:90:25: error: 'n' was not declared in this scope; did you mean 'yn'?
   90 |     for (int i = 0; i < n; i++){
      |                         ^
      |                         yn
Main.cpp:90:25: error: 'n' was not declared in this scope; did you mean 'yn'?
   90 |     for (int i = 0; i < n; i++){
      |                         ^
      |                         yn
Main.cpp:90:25: error: 'n' was not declared in this scope; did you mean 'yn'?
   90 |     for (int i = 0; i < n; i++){
      |                         ^
      |                         yn
Main.cpp:90:21: error: 'i' does not name a type
   90 |     for (int i = 0; i < n; i++){
      |                     ^
Main.cpp:90:28: error: 'i' does not name a type
   90 |     for (int i = 0; i < n; i++){
      |                            ^
Main.cpp:95:15: error: non-local lambda expression cannot have a capture-default
   95 |     auto f = [&](int bully) -> int{
      |               ^
Main.cpp: In lambda function:
Main.cpp:101:26: error: 'x' was not declared in this scope
  101 |         vector<int> tx = x;
      |                          ^
Main.cpp:102:26: error: 'y' was not declared in this scope; did you mean 'yn'?
  102 |         vector<int> ty = y;
      |                          ^
      |                          yn
Main.cpp:104:17: error: 'n' was not declared in this scope; did you mean 'yn'?
  104 |         int r = n - 1;
      |                 ^
      |                 yn
Main.cpp: At global scope:
Main.cpp:160:5: error: expected unqualified-id before 'while'
  160 |     while (lo < hi){
      |     ^~~~~
Main.cpp:169:5: error: 'hi' does not name a type
  169 |     hi = lo;
      |     ^~
Main.cpp:170:5: error: 'lo' does not name a type
  170 |     lo = 0;
      |     ^~
Main.cpp:173:5: error: expected unqualified-id before 'while'
  173 |     while (lo < hi){
      |     ^~~~~
Main.cpp:182:5: error: 'cout' does not name a type
  182 |     cout << f(lo) << '\n';
      |     ^~~~
Main.cpp:183:1: error: expected declaration before '}' token
  183 | }
      | ^