Submission #1246180

#TimeUsernameProblemLanguageResultExecution timeMemory
1246180tochikaPalembang Bridges (APIO15_bridge)C++20
Compilation error
0 ms0 KiB
\#include <bits/stdc++.h>
using namespace std;
using lint = long long;

#define IN "iii.txt"
#define OUT "ooo.txt"
#define MULTI_TEST 0

lint l = 0, r = 0;
priority_queue<lint> under;
priority_queue<lint, vector<lint>, greater<lint>> above;

void add(lint x) {
    int med = (under.size() ? under.top() : 1000000001);

    if (x <= med) {
        under.push(x);
        l += x;
    }

    else {
        above.push(x);
        r += x;
    }

    if (above.size() + 1 < under.size()) {
        int t = under.top();
        under.pop();

        above.push(t);
        r += t;
        l -= t;
    }

    else if (under.size() < above.size()) {
        int t = above.top();
        above.pop();

        under.push(t);
        r -= t;
        l += t;
    }
}

void solve() {
    int k, n;
    cin >> k >> n;

    lint cnt = 0;
    vector<pair<lint, lint>> v = {{0LL, 0LL}};

    for (int i = 0; i < n; i++) {
        char a, b;
        lint x, y;

        cin >> a >> x >> b >> y;

        if (a == b)
            cnt += abs(x - y);

        else v.push_back({x, y});
    }

    sort(v.begin(), v.end(), [&](pair<lint, lint>& m1, pair<lint, lint>& m2){
         return m1.first + m1.second < m2.first + m2.second;
    });

    n = v.size() - 1;
    cnt += n;
    
    vector<lint> pf(n + 1, 0);

    l = r = 0;

    for (int i = 1; i <= n; i++) {
        add(v[i].first);
        add(v[i].second);

        pf[i] = r - l;
    }

    lint ans = pf[n];

    if (k == 2) {
        while (under.size()) under.pop();
        while (above.size()) above.pop();

        l = r = 0;

        for (int i = n; i > 0; i--) {
            add(v[i].first);
            add(v[i].second);

            ans = min(ans, r - l + pf[i - 1]);
        }
    }

    cout << ans + cnt;
}

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

    if (fopen(IN, "r")) {
        freopen(IN, "r", stdin);
        freopen(OUT, "w", stdout);
    }

    int t = 1;
    if (MULTI_TEST) {
        cin >> t;
    }

    for (int i = 1; i <= t; i++) {
        solve();
        cout << '\n';
    }

    return 0;
}

Compilation message (stderr)

bridge.cpp:1:1: error: stray '\' in program
    1 | \#include <bits/stdc++.h>
      | ^
bridge.cpp:1:2: error: stray '#' in program
    1 | \#include <bits/stdc++.h>
      |  ^
bridge.cpp:1:12: error: 'bits' was not declared in this scope
    1 | \#include <bits/stdc++.h>
      |            ^~~~
bridge.cpp:1:17: error: 'stdc' was not declared in this scope; did you mean 'std'?
    1 | \#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
bridge.cpp:1:12: error: 'bits' was not declared in this scope
    1 | \#include <bits/stdc++.h>
      |            ^~~~
bridge.cpp:1:17: error: 'stdc' was not declared in this scope; did you mean 'std'?
    1 | \#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
bridge.cpp:1:12: error: 'bits' was not declared in this scope
    1 | \#include <bits/stdc++.h>
      |            ^~~~
bridge.cpp:1:17: error: 'stdc' was not declared in this scope; did you mean 'std'?
    1 | \#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
bridge.cpp:1:12: error: 'bits' was not declared in this scope
    1 | \#include <bits/stdc++.h>
      |            ^~~~
bridge.cpp:1:17: error: 'stdc' was not declared in this scope; did you mean 'std'?
    1 | \#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
bridge.cpp:1:12: error: 'bits' was not declared in this scope
    1 | \#include <bits/stdc++.h>
      |            ^~~~
bridge.cpp:1:17: error: 'stdc' was not declared in this scope; did you mean 'std'?
    1 | \#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
bridge.cpp:1:12: error: 'bits' was not declared in this scope
    1 | \#include <bits/stdc++.h>
      |            ^~~~
bridge.cpp:1:17: error: 'stdc' was not declared in this scope; did you mean 'std'?
    1 | \#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
bridge.cpp:1:12: error: 'bits' was not declared in this scope
    1 | \#include <bits/stdc++.h>
      |            ^~~~
bridge.cpp:1:17: error: 'stdc' was not declared in this scope; did you mean 'std'?
    1 | \#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
bridge.cpp:1:12: error: 'bits' was not declared in this scope
    1 | \#include <bits/stdc++.h>
      |            ^~~~
bridge.cpp:1:17: error: 'stdc' was not declared in this scope; did you mean 'std'?
    1 | \#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
bridge.cpp:1:12: error: 'bits' was not declared in this scope
    1 | \#include <bits/stdc++.h>
      |            ^~~~
bridge.cpp:1:17: error: 'stdc' was not declared in this scope; did you mean 'std'?
    1 | \#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
bridge.cpp:1:3: error: 'include' does not name a type
    1 | \#include <bits/stdc++.h>
      |   ^~~~~~~
bridge.cpp:10:1: error: 'priority_queue' does not name a type
   10 | priority_queue<lint> under;
      | ^~~~~~~~~~~~~~
bridge.cpp:11:22: error: 'vector' was not declared in this scope
   11 | priority_queue<lint, vector<lint>, greater<lint>> above;
      |                      ^~~~~~
bridge.cpp:11:22: error: 'vector' was not declared in this scope
bridge.cpp:11:22: error: 'vector' was not declared in this scope
bridge.cpp:11:22: error: 'vector' was not declared in this scope
bridge.cpp:11:22: error: 'vector' was not declared in this scope
bridge.cpp:11:22: error: 'vector' was not declared in this scope
bridge.cpp:11:22: error: 'vector' was not declared in this scope
bridge.cpp:11:22: error: 'vector' was not declared in this scope
bridge.cpp:11:22: error: 'vector' was not declared in this scope
bridge.cpp:11:1: error: 'priority_queue' does not name a type
   11 | priority_queue<lint, vector<lint>, greater<lint>> above;
      | ^~~~~~~~~~~~~~
bridge.cpp: In function 'void add(lint)':
bridge.cpp:14:16: error: 'under' was not declared in this scope
   14 |     int med = (under.size() ? under.top() : 1000000001);
      |                ^~~~~
bridge.cpp:22:9: error: 'above' was not declared in this scope
   22 |         above.push(x);
      |         ^~~~~
bridge.cpp:26:9: error: 'above' was not declared in this scope
   26 |     if (above.size() + 1 < under.size()) {
      |         ^~~~~
bridge.cpp: In function 'void solve()':
bridge.cpp:47:5: error: 'cin' was not declared in this scope
   47 |     cin >> k >> n;
      |     ^~~
bridge.cpp:50:12: error: 'pair' was not declared in this scope
   50 |     vector<pair<lint, lint>> v = {{0LL, 0LL}};
      |            ^~~~
bridge.cpp:50:5: error: 'vector' was not declared in this scope
   50 |     vector<pair<lint, lint>> v = {{0LL, 0LL}};
      |     ^~~~~~
bridge.cpp:50:21: error: expected primary-expression before ',' token
   50 |     vector<pair<lint, lint>> v = {{0LL, 0LL}};
      |                     ^
bridge.cpp:50:27: error: expected primary-expression before '>' token
   50 |     vector<pair<lint, lint>> v = {{0LL, 0LL}};
      |                           ^~
bridge.cpp:50:30: error: 'v' was not declared in this scope
   50 |     vector<pair<lint, lint>> v = {{0LL, 0LL}};
      |                              ^
bridge.cpp:59:20: error: 'abs' was not declared in this scope
   59 |             cnt += abs(x - y);
      |                    ^~~
bridge.cpp:64:34: error: 'pair' is not a type
   64 |     sort(v.begin(), v.end(), [&](pair<lint, lint>& m1, pair<lint, lint>& m2){
      |                                  ^~~~
bridge.cpp:64:38: error: expected ',' or '...' before '<' token
   64 |     sort(v.begin(), v.end(), [&](pair<lint, lint>& m1, pair<lint, lint>& m2){
      |                                      ^
bridge.cpp: In lambda function:
bridge.cpp:65:17: error: 'm1' was not declared in this scope
   65 |          return m1.first + m1.second < m2.first + m2.second;
      |                 ^~
bridge.cpp:65:40: error: 'm2' was not declared in this scope
   65 |          return m1.first + m1.second < m2.first + m2.second;
      |                                        ^~
bridge.cpp: In function 'void solve()':
bridge.cpp:64:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   64 |     sort(v.begin(), v.end(), [&](pair<lint, lint>& m1, pair<lint, lint>& m2){
      |     ^~~~
      |     short
bridge.cpp:71:16: error: expected primary-expression before '>' token
   71 |     vector<lint> pf(n + 1, 0);
      |                ^
bridge.cpp:71:18: error: 'pf' was not declared in this scope
   71 |     vector<lint> pf(n + 1, 0);
      |                  ^~
bridge.cpp:85:16: error: 'under' was not declared in this scope
   85 |         while (under.size()) under.pop();
      |                ^~~~~
bridge.cpp:86:16: error: 'above' was not declared in this scope
   86 |         while (above.size()) above.pop();
      |                ^~~~~
bridge.cpp:94:19: error: 'min' was not declared in this scope
   94 |             ans = min(ans, r - l + pf[i - 1]);
      |                   ^~~
bridge.cpp:98:5: error: 'cout' was not declared in this scope
   98 |     cout << ans + cnt;
      |     ^~~~
bridge.cpp: In function 'int main()':
bridge.cpp:102:5: error: 'ios' has not been declared
  102 |     ios::sync_with_stdio(false);
      |     ^~~
bridge.cpp:103:5: error: 'cin' was not declared in this scope
  103 |     cin.tie(nullptr);
      |     ^~~
bridge.cpp:105:9: error: 'fopen' was not declared in this scope
  105 |     if (fopen(IN, "r")) {
      |         ^~~~~
bridge.cpp:1:1: note: 'fopen' is defined in header '<cstdio>'; did you forget to '#include <cstdio>'?
  +++ |+#include <cstdio>
    1 | \#include <bits/stdc++.h>
bridge.cpp:106:26: error: 'stdin' was not declared in this scope
  106 |         freopen(IN, "r", stdin);
      |                          ^~~~~
bridge.cpp:106:26: note: 'stdin' is defined in header '<cstdio>'; did you forget to '#include <cstdio>'?
bridge.cpp:106:9: error: 'freopen' was not declared in this scope
  106 |         freopen(IN, "r", stdin);
      |         ^~~~~~~
bridge.cpp:107:27: error: 'stdout' was not declared in this scope
  107 |         freopen(OUT, "w", stdout);
      |                           ^~~~~~
bridge.cpp:107:27: note: 'stdout' is defined in header '<cstdio>'; did you forget to '#include <cstdio>'?
bridge.cpp:117:9: error: 'cout' was not declared in this scope
  117 |         cout << '\n';
      |         ^~~~