Submission details
Task:Elevator Trouble
Sender:Pekka Väänänen
Submission time:2016-09-06 13:29:31 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.05 sdetails
#2ACCEPTED0.06 sdetails
#30.45 sdetails
#4--details
#5ACCEPTED0.05 sdetails
#6--details
#70.04 sdetails
#80.46 sdetails
#9ACCEPTED0.06 sdetails
#100.05 sdetails
#110.45 sdetails
#12ACCEPTED0.06 sdetails

Code

#include <bits/stdc++.h>

using namespace std;

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

    // each pair contains the current position and
    // also a set of all visited positions so we
    // can terminate the search when the current position
    // is already in the visited ones
    queue<pair<int, set<int>>> to_visit;
    int shortest = -1;

    to_visit.push(make_pair(start, set<int>()));

    while (to_visit.size() > 0) {
        // pop a pair from stack
        auto elem = to_visit.front();
        to_visit.pop();

        // check if the current position is goal

        if (elem.first == goal) {
            // if it is, we are done
            shortest = elem.second.size() + 1;
            break;
        }

        // check if current position is invalid
        if (elem.first < 1 || elem.first > floors) {
            // if true, continue
            continue;
        }

        // check if the current position is already in the set
        if (elem.second.count(elem.first)) {
            // if it is, continue
            continue;
        }

        // create a new set for both children where the current position is added
        set<int> newset = elem.second;
        newset.insert(elem.first);

        // push the two child nodes
        to_visit.push(make_pair(elem.first + u, newset));
        to_visit.push(make_pair(elem.first + d, newset));
    }

    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: ACCEPTED

input
100 2 1 1 0

correct output
use the stairs

user output
use the stairs

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: ACCEPTED

input
1000000 1 1000000 0 0

correct output
use the stairs

user output
use the stairs

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: ACCEPTED

input
10 5 4 6 2

correct output
use the stairs

user output
use the stairs

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: ACCEPTED

input
100 50 51 4 6

correct output
use the stairs

user output
use the stairs