CSES - KILO 2016 0/5 - Results
Submission details
Task:Elevator Trouble
Sender:Jerry Mesimäki
Submission time:2016-09-06 16:43:11 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.05 sdetails
#2ACCEPTED0.06 sdetails
#3ACCEPTED0.06 sdetails
#4ACCEPTED0.05 sdetails
#5ACCEPTED0.06 sdetails
#6ACCEPTED0.07 sdetails
#7ACCEPTED0.06 sdetails
#8ACCEPTED0.05 sdetails
#9ACCEPTED0.05 sdetails
#10ACCEPTED0.04 sdetails
#11ACCEPTED0.04 sdetails
#12ACCEPTED0.05 sdetails

Code

#include <bits/stdc++.h>

using namespace std;



int main()
{
	int floors;
	int start;
	int goal;
	int up;
	int down;

	cin >> floors >> start >> goal >> up >> down;
	vector<int> visited(floors+1, false);

	queue<pair<int, int>> floorQue;

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

	int howMany = -1;

	while (!floorQue.empty()) {

		pair<int, int> toHandle = floorQue.front();
		floorQue.pop();

		// cout << "at floor " << toHandle.first << " with this many steps: " << toHandle.second << "\n";

		if (visited[toHandle.first]) continue;

		// cout << "not found from visited\n";

		if (toHandle.first > floors || toHandle.first < 1) continue;

		// cout << "within correct range\n";

		if (toHandle.first == goal) {
			howMany = toHandle.second;
			break;
		}

		// cout << "not goal\n";

		visited[toHandle.first] = true;

		pair<int, int> toPushUp = make_pair(toHandle.first+up, toHandle.second + 1);
		floorQue.push(toPushUp);

		pair<int, int> toPushDown = make_pair(toHandle.first-down, toHandle.second + 1);
		floorQue.push(toPushDown);
	}

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


	return 0;
}

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

input
1000000 1 1000000 1 1

correct output
999999

user output
999999

Test 4

Verdict: ACCEPTED

input
1000000 1 1000000 0 1

correct output
use the stairs

user output
use the stairs

Test 5

Verdict: ACCEPTED

input
1000000 1 1000000 0 0

correct output
use the stairs

user output
use the stairs

Test 6

Verdict: ACCEPTED

input
1000000 1 1000000 1 0

correct output
999999

user output
999999

Test 7

Verdict: ACCEPTED

input
1000000 1000000 1 0 1

correct output
999999

user output
999999

Test 8

Verdict: ACCEPTED

input
1000000 2 99999 2 1

correct output
50000

user output
50000

Test 9

Verdict: ACCEPTED

input
10 5 4 6 2

correct output
use the stairs

user output
use the stairs

Test 10

Verdict: ACCEPTED

input
1000000 1000000 1000000 100000...

correct output
0

user output
0

Test 11

Verdict: ACCEPTED

input
456789 2 456789 2 1

correct output
228395

user output
228395

Test 12

Verdict: ACCEPTED

input
100 50 51 4 6

correct output
use the stairs

user output
use the stairs