Submission details
Task:Elevator Trouble
Sender:Häviö Life
Submission time:2015-09-02 16:54:35 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#10.06 sdetails
#2--details
#30.05 sdetails
#4--details
#5--details
#60.06 sdetails
#7--details
#80.05 sdetails
#9ACCEPTED0.05 sdetails
#10ACCEPTED0.05 sdetails
#110.05 sdetails
#12ACCEPTED0.06 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:27:17: warning: iteration 1000000u invokes undefined behavior [-Waggressive-loop-optimizations]
         dp[i]=-1;
                 ^
input/code.cpp:26:5: note: containing loop
     for(int i=0; i<1000001; i++)
     ^

Code

#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <unordered_set>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <fstream>
#include <set>
#include <map>

#define MOD 1000000007
#define ll long long
#define N 1000000
#define float double

using namespace std;

int dp[1000000];

int main(){
    for(int i=0; i<1000001; i++)
        dp[i]=-1;
    int f,s,g,u,d;
    cin>>f>>s>>g>>u>>d;
    s--;
    g--;

    dp[s]=0;

    queue<int> j;
    j.push(s);
    while(j.size()){
        int a=j.front();
        j.pop();

        if(a+u<f&&dp[a+u]!=-1){
            dp[a+u]=dp[a]+1;
            j.push(a+u);
        }

        if(a-d>0&&dp[a-d]!=-1){
            dp[a-u]=dp[a]+1;
            j.push(a-u);
        }
    }

    if(dp[g]==-1)
        cout<<"use the stairs\n";
    else
        cout<<dp[g]<<endl;
    return 0;
}

Test details

Test 1

Verdict:

input
10 1 10 2 1

correct output
6

user output
use the stairs

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
use the stairs

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
use the stairs

Test 7

Verdict:

input
1000000 1000000 1 0 1

correct output
999999

user output
(empty)

Test 8

Verdict:

input
1000000 2 99999 2 1

correct output
50000

user output
use the stairs

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:

input
456789 2 456789 2 1

correct output
228395

user output
use the stairs

Test 12

Verdict: ACCEPTED

input
100 50 51 4 6

correct output
use the stairs

user output
use the stairs