Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.ByteArrayInputStream;
- import java.util.Scanner;
- public class Main {
- static void fakeInput() {
- String test = "6 7 3\n" +
- "0 0\n" +
- "2 2\n" +
- "-2 2\n" +
- "3 -1";
- System.setIn(new ByteArrayInputStream(test.getBytes()));
- }
- public static void main(String[] args) {
- fakeInput();
- Scanner scanner = new Scanner(System.in);
- int N = scanner.nextInt();
- int M = scanner.nextInt();
- int[][] field = new int[N][M];
- int startValue = 1;
- int row = 0;
- int col = 0;
- for (row = 0; row < field.length; row++) {
- for (col = 0; col < field[row].length; col++) {
- field[row][col] = startValue;
- startValue++;
- }
- }
- int J = scanner.nextInt();
- int R = scanner.nextInt();
- int C = scanner.nextInt();
- long sum = field[R][C];
- int jumps = 0;
- field[R][C] = 0;
- boolean escaped = true;
- int[] RowMoves = new int[J];
- int[] Colmoves = new int[J];
- for (int i = 0; i < J; i++) {
- int RowMove = scanner.nextInt();
- int ColMove = scanner.nextInt();
- RowMoves[i] = RowMove;
- Colmoves[i] = ColMove;
- R += RowMove;
- C += ColMove;
- if (R >= N || C >= M) {
- escaped = true;
- break;
- } else if (field[R][C] == 0) {
- escaped = false;
- break;
- }
- sum += field[R][C];
- jumps++;
- field[R][C] = 0;
- if (i + 1 == J) {
- for (int k = 0; k < J; k++) {
- RowMove = RowMoves[k];
- ColMove = Colmoves[k];
- R += RowMove;
- C += ColMove;
- if (R >= N || C >= M) {
- escaped = true;
- break;
- } else if (field[R][C] == 0) {
- escaped = false;
- break;
- }
- sum += field[R][C];
- jumps++;
- field[R][C] = 0;
- }
- }
- }
- if(escaped == true){
- System.out.println("escaped" + " " + sum);
- }else if(escaped == false){
- System.out.println("caught" + " " + jumps);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement