Submission details
Task:Elevator Trouble
Sender:Pekka Väänänen
Submission time:2016-09-05 19:35:59 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.05 sdetails
#20.32 sdetails
#30.32 sdetails
#40.32 sdetails
#50.31 sdetails
#60.31 sdetails
#70.05 sdetails
#80.32 sdetails
#90.14 sdetails
#100.05 sdetails
#110.32 sdetails
#120.14 sdetails

Code

#include <bits/stdc++.h>

using namespace std;

static inline double func(double x)
{
    return exp(x) + sqrt(x);
}

int main() {
    cin.sync_with_stdio(false);
    int floors, start, goal, u, d;
    cin >> floors >> start >> goal >> u >> d;

    queue<pair<int, int>> to_visit;
    int shortest = -1;

    to_visit.push(make_pair(start, 0));

    const int MAX_LEVELS = 25;

    while (shortest == -1) {
        auto elem = to_visit.front();
        to_visit.pop();
        if (elem.first == goal) {
            shortest = elem.second + 1;
            break;
        }

        if (elem.second == MAX_LEVELS) {
            break;
        }

        if (elem.first < 1 || elem.first > floors) {
            continue;
        }

        to_visit.push(make_pair(elem.first + u, elem.second + 1));
        to_visit.push(make_pair(elem.first + d, elem.second + 1));
    }

    if (shortest == -1) {
        cout << "use the stairs\n";
    } else  {
        cout << shortest << "\n";
    }

}

Test details

Test 1

Verdict: ACCEPTED

input
10 1 10 2 1

correct output
6

user output
6

Test 2

Verdict:

input
100 2 1 1 0

correct output
use the stairs

user output
(empty)

Test 3

Verdict:

input
1000000 1 1000000 1 1

correct output
999999

user output
(empty)

Test 4

Verdict:

input
1000000 1 1000000 0 1

correct output
use the stairs

user output
(empty)

Test 5

Verdict:

input
1000000 1 1000000 0 0

correct output
use the stairs

user output
(empty)

Test 6

Verdict:

input
1000000 1 1000000 1 0

correct output
999999

user output
(empty)

Test 7

Verdict:

input
1000000 1000000 1 0 1

correct output
999999

user output
use the stairs

Test 8

Verdict:

input
1000000 2 99999 2 1

correct output
50000

user output
(empty)

Test 9

Verdict:

input
10 5 4 6 2

correct output
use the stairs

user output
(empty)

Test 10

Verdict:

input
1000000 1000000 1000000 100000...

correct output
0

user output
1

Test 11

Verdict:

input
456789 2 456789 2 1

correct output
228395

user output
(empty)

Test 12

Verdict:

input
100 50 51 4 6

correct output
use the stairs

user output
(empty)