Submission details
Task:Elevator Trouble
Sender:Tuukka Korhonen
Submission time:2016-08-21 20:16:59 +0300
Language:Java
Status:COMPILE ERROR

Compiler report

input/elev.java:2: error: class ElevatorTrouble is public, should be declared in a file named ElevatorTrouble.java
public class ElevatorTrouble {
       ^
1 error

Code

import java.util.*;
public class ElevatorTrouble {
public static void main(String[] args) {
	IO io = new IO();
	
	int f = io.nextInt();
	int s = io.nextInt();
	int g = io.nextInt();
	int u = io.nextInt();
	int d = io.nextInt();
	
	int[] dist = new int[f + 1];
	Arrays.fill(dist, -1);
	
	ArrayDeque<Integer> Q = new ArrayDeque<>();
	dist[s] = 0;
	Q.push(s);
	
	while(!Q.isEmpty()) {
		int v = Q.remove();
		
		int x = v - d;
		int y = v + u;
		
		if(x >= 1 && dist[x] == -1) {
			dist[x] = dist[v] + 1;
			Q.push(x);
		}
		
		if(y <= f && dist[y] == -1) {
			dist[y] = dist[v] + 1;
			Q.push(y);
		}
	}
	
	if(dist[g] == -1) {
		io.println("use the stairs");
	} else {
		io.println(dist[g]);
	}
	
	io.close();
}
}