Submission #1069637

#TimeUsernameProblemLanguageResultExecution timeMemory
1069637IgnutRoller Coaster Railroad (IOI16_railroad)C++17
0 / 100
183 ms25812 KiB
// Ignut

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll INF = 1e18 + 123;
const int inf = 1e9 + 123;

ll plan_roller_coaster(vector<int> s, vector<int> t) {
    int n = s.size();
    multiset<pair<int, int>> ms;
    for (int i = 0; i < n; i ++) ms.insert({s[i], -t[i]});
    int speed = 1;
    int se = -1, te = -1;
    for (int i = 0; i < n; i ++) {
        auto it = ms.lower_bound({speed, -inf});
        if (it == ms.end())
            return 1;
        auto [S, T] = *it;
        ms.erase(it);
        speed = -T;

        if (i == n - 1) continue;
        if (ms.lower_bound({speed, -inf}) == ms.end()) {
            se = S, te = -T;
            it ++;
            if (it == ms.end()) 
                return 1ll;
            auto [SS, TT] = *it;
            speed = -TT;
            // ms.insert({S, T});
            ms.erase(it);
            // cout << "bad " << S << ' ' << -T << '\n';
            // cout << "get2 " << SS << ' ' << -TT << '\n';
        }
        else {
            // cout << "get " << S << ' ' << -T << '\n';
        }
    }
    if (se == -1 || se >= speed)
        return 0ll;
    else
        return 1ll;
}

/*
4
13 11
20 16
7 7
13 18

*/

Compilation message (stderr)

railroad.cpp: In function 'll plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:16:18: warning: variable 'te' set but not used [-Wunused-but-set-variable]
   16 |     int se = -1, te = -1;
      |                  ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...