Submission #297306

#TimeUsernameProblemLanguageResultExecution timeMemory
297306AaronNaiduPalembang Bridges (APIO15_bridge)C++14
Compilation error
0 ms0 KiB
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> k >> n;
    ll minSum = 0;
    numLeft = numRight = distFrom0 = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> p >> s >> q >> t;
        if (p == q)
        {
            minSum += abs(t - s);
        }
        else
        {
            minSum += 1 + abs(t - s);
            ll b = max(t, s);
            ll a = min(t, s);
            events.push_back({a, -1});
            events.push_back({b, 1});
            numRight++;
            distFrom0 += a;
        }
    }
    //cout << "Min sum is " << minSum << "\n";
    //cout << "Initial dist: " << distFrom0 << "\n";
    sort(events.begin(), events.end());
    ll prevLocation = 0;
    ll finAns = 1000000000000000;
    if (events.size() == 0)
    {
        finAns = minSum;
    }
    for (int i = 0; i < events.size(); i++)
    {
        ll currLocation = events[i].first;
        distFrom0 -= numRight * (currLocation - prevLocation);
        distFrom0 += numLeft * (currLocation - prevLocation);
        if (events[i].second == -1)
        {
            numRight--;
        }
        else
        {
            numLeft++;
        }
        finAns = min(finAns, minSum + 2 * distFrom0);
        //cout << "At location " << currLocation << " dist is " << distFrom0 << '\n'; 
        prevLocation = currLocation;
    }
    cout << finAns << "\n";    
}

Compilation message (stderr)

bridge.cpp: In function 'int main()':
bridge.cpp:2:5: error: 'ios_base' has not been declared
    2 |     ios_base::sync_with_stdio(false);
      |     ^~~~~~~~
bridge.cpp:3:5: error: 'cin' was not declared in this scope
    3 |     cin.tie(NULL);
      |     ^~~
bridge.cpp:3:13: error: 'NULL' was not declared in this scope
    3 |     cin.tie(NULL);
      |             ^~~~
bridge.cpp:1:1: note: 'NULL' is defined in header '<cstddef>'; did you forget to '#include <cstddef>'?
  +++ |+#include <cstddef>
    1 | int main() {
bridge.cpp:4:5: error: 'cout' was not declared in this scope
    4 |     cout.tie(NULL);
      |     ^~~~
bridge.cpp:5:12: error: 'k' was not declared in this scope
    5 |     cin >> k >> n;
      |            ^
bridge.cpp:5:17: error: 'n' was not declared in this scope
    5 |     cin >> k >> n;
      |                 ^
bridge.cpp:6:5: error: 'll' was not declared in this scope
    6 |     ll minSum = 0;
      |     ^~
bridge.cpp:7:5: error: 'numLeft' was not declared in this scope
    7 |     numLeft = numRight = distFrom0 = 0;
      |     ^~~~~~~
bridge.cpp:7:15: error: 'numRight' was not declared in this scope
    7 |     numLeft = numRight = distFrom0 = 0;
      |               ^~~~~~~~
bridge.cpp:7:26: error: 'distFrom0' was not declared in this scope
    7 |     numLeft = numRight = distFrom0 = 0;
      |                          ^~~~~~~~~
bridge.cpp:10:16: error: 'p' was not declared in this scope
   10 |         cin >> p >> s >> q >> t;
      |                ^
bridge.cpp:10:21: error: 's' was not declared in this scope
   10 |         cin >> p >> s >> q >> t;
      |                     ^
bridge.cpp:10:26: error: 'q' was not declared in this scope
   10 |         cin >> p >> s >> q >> t;
      |                          ^
bridge.cpp:10:31: error: 't' was not declared in this scope
   10 |         cin >> p >> s >> q >> t;
      |                               ^
bridge.cpp:13:13: error: 'minSum' was not declared in this scope
   13 |             minSum += abs(t - s);
      |             ^~~~~~
bridge.cpp:13:23: error: 'abs' was not declared in this scope
   13 |             minSum += abs(t - s);
      |                       ^~~
bridge.cpp:17:13: error: 'minSum' was not declared in this scope
   17 |             minSum += 1 + abs(t - s);
      |             ^~~~~~
bridge.cpp:17:27: error: 'abs' was not declared in this scope
   17 |             minSum += 1 + abs(t - s);
      |                           ^~~
bridge.cpp:18:15: error: expected ';' before 'b'
   18 |             ll b = max(t, s);
      |               ^~
      |               ;
bridge.cpp:19:15: error: expected ';' before 'a'
   19 |             ll a = min(t, s);
      |               ^~
      |               ;
bridge.cpp:20:13: error: 'events' was not declared in this scope
   20 |             events.push_back({a, -1});
      |             ^~~~~~
bridge.cpp:20:31: error: 'a' was not declared in this scope
   20 |             events.push_back({a, -1});
      |                               ^
bridge.cpp:21:31: error: 'b' was not declared in this scope
   21 |             events.push_back({b, 1});
      |                               ^
bridge.cpp:28:10: error: 'events' was not declared in this scope
   28 |     sort(events.begin(), events.end());
      |          ^~~~~~
bridge.cpp:28:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   28 |     sort(events.begin(), events.end());
      |     ^~~~
      |     short
bridge.cpp:29:7: error: expected ';' before 'prevLocation'
   29 |     ll prevLocation = 0;
      |       ^~~~~~~~~~~~~
      |       ;
bridge.cpp:30:7: error: expected ';' before 'finAns'
   30 |     ll finAns = 1000000000000000;
      |       ^~~~~~~
      |       ;
bridge.cpp:33:9: error: 'finAns' was not declared in this scope
   33 |         finAns = minSum;
      |         ^~~~~~
bridge.cpp:33:18: error: 'minSum' was not declared in this scope
   33 |         finAns = minSum;
      |                  ^~~~~~
bridge.cpp:37:11: error: expected ';' before 'currLocation'
   37 |         ll currLocation = events[i].first;
      |           ^~~~~~~~~~~~~
      |           ;
bridge.cpp:38:34: error: 'currLocation' was not declared in this scope
   38 |         distFrom0 -= numRight * (currLocation - prevLocation);
      |                                  ^~~~~~~~~~~~
bridge.cpp:38:49: error: 'prevLocation' was not declared in this scope
   38 |         distFrom0 -= numRight * (currLocation - prevLocation);
      |                                                 ^~~~~~~~~~~~
bridge.cpp:48:9: error: 'finAns' was not declared in this scope
   48 |         finAns = min(finAns, minSum + 2 * distFrom0);
      |         ^~~~~~
bridge.cpp:48:30: error: 'minSum' was not declared in this scope
   48 |         finAns = min(finAns, minSum + 2 * distFrom0);
      |                              ^~~~~~
bridge.cpp:48:18: error: 'min' was not declared in this scope; did you mean 'main'?
   48 |         finAns = min(finAns, minSum + 2 * distFrom0);
      |                  ^~~
      |                  main
bridge.cpp:52:13: error: 'finAns' was not declared in this scope
   52 |     cout << finAns << "\n";
      |             ^~~~~~