| Task: | Elevator Trouble |
| Sender: | Pekka Väänänen |
| Submission time: | 2016-09-06 13:29:31 +0300 |
| Language: | C++ |
| Status: | READY |
| Result: | RUNTIME ERROR |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.05 s | details |
| #2 | ACCEPTED | 0.06 s | details |
| #3 | RUNTIME ERROR | 0.45 s | details |
| #4 | TIME LIMIT EXCEEDED | -- | details |
| #5 | ACCEPTED | 0.05 s | details |
| #6 | TIME LIMIT EXCEEDED | -- | details |
| #7 | WRONG ANSWER | 0.04 s | details |
| #8 | RUNTIME ERROR | 0.46 s | details |
| #9 | ACCEPTED | 0.06 s | details |
| #10 | WRONG ANSWER | 0.05 s | details |
| #11 | RUNTIME ERROR | 0.45 s | details |
| #12 | ACCEPTED | 0.06 s | details |
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: RUNTIME ERROR
| input |
|---|
| 1000000 1 1000000 1 1 |
| correct output |
|---|
| 999999 |
| user output |
|---|
| (empty) |
Test 4
Verdict: TIME LIMIT EXCEEDED
| 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: TIME LIMIT EXCEEDED
| input |
|---|
| 1000000 1 1000000 1 0 |
| correct output |
|---|
| 999999 |
| user output |
|---|
| (empty) |
Test 7
Verdict: WRONG ANSWER
| input |
|---|
| 1000000 1000000 1 0 1 |
| correct output |
|---|
| 999999 |
| user output |
|---|
| use the stairs |
Test 8
Verdict: RUNTIME ERROR
| 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: WRONG ANSWER
| input |
|---|
| 1000000 1000000 1000000 100000... |
| correct output |
|---|
| 0 |
| user output |
|---|
| 1 |
Test 11
Verdict: RUNTIME ERROR
| 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 |
