Task: | Elevator Trouble |
Sender: | Jerry Mesimäki |
Submission time: | 2016-09-06 16:43:11 +0300 |
Language: | C++ |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.05 s | details |
#2 | ACCEPTED | 0.06 s | details |
#3 | ACCEPTED | 0.06 s | details |
#4 | ACCEPTED | 0.05 s | details |
#5 | ACCEPTED | 0.06 s | details |
#6 | ACCEPTED | 0.07 s | details |
#7 | ACCEPTED | 0.06 s | details |
#8 | ACCEPTED | 0.05 s | details |
#9 | ACCEPTED | 0.05 s | details |
#10 | ACCEPTED | 0.04 s | details |
#11 | ACCEPTED | 0.04 s | details |
#12 | ACCEPTED | 0.05 s | details |
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 |