fork download
  1. import java.util.Scanner;
  2.  
  3. class dynamic {
  4.  
  5. static int spaces = 0;
  6.  
  7. public static void main(String arg[]) {
  8. int i = 0;
  9. Scanner s = new Scanner(System.in);
  10. int num[] = new int[8];
  11. while (i < 8) {
  12. num[i] = s.nextInt();
  13. i++;
  14. }
  15.  
  16. int b = findmin(num);
  17. System.out.println(b);
  18. }
  19.  
  20. public static int findmin(int num[]) {
  21. if (num.length == 0)
  22. return 0;
  23.  
  24. return findmin(num, 0, num.length - 1);
  25. }
  26.  
  27. public static int findmin(int num[], int first, int last) {
  28. ++spaces;
  29. printSpaces();
  30. System.out.printf("findmin(first=%d, last=%d) {\n", first, last);
  31. if (first == last) {
  32. printSpaces();
  33. System.out.printf("} => %d\n", num[first]);
  34. --spaces;
  35. return num[first];
  36. }
  37. if (first + 1 == last) {
  38. int min = Math.min(num[first], num[last]);
  39. printSpaces();
  40. System.out.printf("} => %d\n", min);
  41. --spaces;
  42. return min;
  43. }
  44.  
  45. int min1 = findmin(num, (last / 2) + 1, last);
  46. int min2 = findmin(num, first, last / 2);
  47.  
  48. if (min1 > min2) {
  49. printSpaces();
  50. System.out.printf("} => %d\n", min2);
  51. --spaces;
  52. return min2;
  53. } else {
  54. printSpaces();
  55. System.out.printf("} => %d\n", min1);
  56. --spaces;
  57. return min1;
  58. }
  59.  
  60. }
  61.  
  62. private static void printSpaces() {
  63. for (int i = 0; i < spaces; i++) {
  64. System.out.print(" ");
  65. }
  66. }
  67.  
  68. }
Runtime error #stdin #stdout 0.29s 380800KB
stdin
1 2 3 4 5 6 7 8
stdout
  findmin(first=0, last=7) {
    findmin(first=4, last=7) {
      findmin(first=4, last=7) {
        findmin(first=4, last=7) {
          findmin(first=4, last=7) {
            findmin(first=4, last=7) {
              findmin(first=4, last=7) {
                findmin(first=4, last=7) {
                  findmin(first=4, last=7) {
                    findmin(first=4, last=7) {
                      findmin(first=4, last=7) {
                        findmin(first=4, last=7) {
                          findmin(first=4, last=7) {
                            findmin(first=4, last=7) {
                              findmin(first=4, last=7) {
                                findmin(first=4, last=7) {
                                  findmin(first=4, last=7) {
                                    findmin(first=4, last=7) {
                                      findmin(first=4, last=7) {
                                        findmin(first=4, last=7) {
                                          findmin(first=4, last=7) {
                                            findmin(first=4, last=7) {
                                              findmin(first=4, last=7) {
                                                findmin(first=4, last=7) {
                                                  findmin(first=4, last=7) {
                                                    findmin(first=4, last=7) {
                                                      findmin(first=4, last=7) {
                                                        findmin(first=4, last=7) {
                                                          findmin(first=4, last=7) {
                                                            findmin(first=4, last=7) {
                                                              findmin(first=4, last=7) {
                                                                findmin(first=4, last=7) {
                                                                  findmin(first=4, last=7) {
                                                                    findmin(first=4, last=7) {
                                                                      findmin(first=4, last=7) {
                                                                        findmin(first=4, last=7) {
                                                                          findmin(first=4, last=7) {
                                                                            findmin(first=4, last=7) {
                                                                              findmin(first=4, last=7) {
                                                                                findmin(first=4, last=7) {
                                                                                  findmin(first=4, last=7) {
                                                                                    findmin(first=4, last=7) {
                                                                                      findmin(first=4, last=7) {
                                                                                        findmin(first=4, last=7) {
                                                                                          findmin(first=4, last=7) {
                                                                                            findmin(first=4, last=7) {
                                                                                              findmin(first=4, last=7) {
                                                                                                findmin(first=4, last=7) {
                                                                                                  findmin(first=4, last=7) {
                                                                                                    findmin(first=4, last=7) {
                                                                                                      findmin(first=4, last=7) {
                                                                                                        findmin(first=4, last=7) {
                                                                                                          findmin(first=4, last=7) {
                                                                                                            findmin(first=4, last=7) {
                                                                                                              findmin(first=4, last=7) {
                                                                                                                findmin(first=4, last=7) {
                                                                                                                  findmin(first=4, last=7) {
                                                                                                                    findmin(first=4, last=7) {
                                                                                                                      findmin(first=4, last=7) {
                                                                                                                        findmin(first=4, last=7) {
                                                                                                                          findmin(first=4, last=7) {
                                                                                                                            findmin(first=4, last=7) {
                                                                                                                              findmin(first=4, last=7) {
                                                                                                                                findmin(first=4, last=7) {
                                                                                                                                  findmin(first=4, last=7) {
                                                                                                                                    findmin(first=4, last=7) {
                                                                                                                                      findmin(first=4, last=7) {
                                                                                                                                        findmin(first=4, last=7) {
                                                                                                                                          findmin(first=4, last=7) {
                                                                                                                                            findmin(first=4, last=7) {
                                                                                                                                              findmin(first=4, last=7) {
                                                                                                                                                findmin(first=4, last=7) {
                                                                                                                                                  findmin(first=4, last=7) {
                                                                                                                                                    findmin(first=4, last=7) {
                                                                                                                                                      findmin(first=4, last=7) {
                                                                                                                                                        findmin(first=4, last=7) {
                                                                                                                                                          findmin(first=4, last=7) {
                                                                                                                                                            findmin(first=4, last=7) {
                                                                                                                                                              findmin(first=4, last=7) {
                                                                                                                                                                findmin(first=4, last=7) {
                                                                                                                                                                  findmin(first=4, last=7) {
                                                                                                                                                                    findmin(first=4, last=7) {
                                                                                                                                                                      findmin(first=4, last=7) {
                                                                                                                                                                        findmin(first=4, last=7) {
                                                                                                                                                                          findmin(first=4, last=7) {
                                                                                                                                                                            findmin(first=4, last=7) {
                                                                                                                                                                              findmin(first=4, last=7) {
                                                                                                                                                                                findmin(first=4, last=7) {
                                                                                                                                                                                  findmin(first=4, last=7) {
                                                                                                                                                                                    findmin(first=4, last=7) {
                                                                                                                                                                                      findmin(first=4, last=7) {
                                                                                                                                                                                        findmin(first=4, last=7) {
                                                                                                                                                                                          findmin(first=4, last=7) {
                                                                                                                                                                                            findmin(first=4, last=7) {
                                                                                                                                                                                              findmin(first=4, last=7) {
                                                                                                                                                                                                findmin(first=4, last=7) {
                                                                                                                                                                                                  findmin(first=4, last=7) {
                                                                                                                                                                                                    findmin(first=4, last=7) {
                                                                                                                                                                                                      findmin(first=4, last=7) {
                                                                                                                                                                                                        findmin(first=4, last=7) {
                                                                                                                                                                                                          findmin(first=4, last=7) {
                                                                                                                                                                                                            findmin(first=4, last=7) {
                                                                                                                                                                                                              findmin(first=4, last=7) {
                                                                                                                                                                                                                findmin(first=4, last=7) {
                                                                                                                                                                                                                  findmin(first=4, last=7) {
                                                                                                                                                                                                                    findmin(first=4, last=7) {
                                                                                                                                                                                                                      findmin(first=4, last=7) {
                                                                                                                                                                                                                        findmin(first=4, last=7) {
                                                                                                                                                                                                                          findmin(first=4, last=7) {
                                                                                                                                                                                                                            findmin(first=4, last=7) {
                                                                                                                                                                                                                              findmin(first=4, last=7) {
                                                                                                                                                                                                                                findmin(first=4, last=7) {
                                                                                                                                                                                                                                  findmin(first=4, last=7) {
                                                                                                                                                                                                                                    findmin(first=4, last=7) {
                                                                                                                                                                                                                                      findmin(first=4, last=7) {
                                                                                                                                                                                                                                        findmin(first=4, last=7) {
                                                                                                                                                                                                                                          findmin(first=4, last=7) {
                                                                                                                                                                                                                                            findmin(first=4, last=7) {
                                                                                                                                                                                                                                              findmin(first=4, last=7) {
                                                                                                                                                                                                                                                findmin(first=4, last=7) {
                                                                                                                                                                                                                                                  findmin(first=4, last=7) {
                                                                                                                                                                                                                                                    findmin(first=4, last=7) {
                                                                                                                                                                                                                                                      findmin(first=4, last=7) {
                                                                                                                                                                                                                                                        findmin(first=4, last=7) {
                                                                                                                                                                                                                                                          findmin(first=4, last=7) {
                                                                                                                                                                                                                                                            findmin(first=4, last=7) {
                                                                                                                                                                                                                                                              findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                  findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                    findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                      findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                        findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                          findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                            findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                              findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                  findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                    findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                      findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                        findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                          findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                            findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                              findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                  findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                    findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                      findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                        findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                          findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                            findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                              findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                  findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                    findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                      findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                        findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                          findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                            findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                              findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                  findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                    findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                      findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                        findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                          findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                            findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                              findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                  findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                    findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                      findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                        findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                          findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                            findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                              findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                  findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                    findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                      findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                        findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                          findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                            findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                              findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                  findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                    findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                      findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                        findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                          findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                            findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                              findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                  findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                    findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                      findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                        findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                          findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                            findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                              findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                  findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                    findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                      findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                        findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                          findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                            findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                              findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                  findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                    findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                      findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                        findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                          findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                            findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                              findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                  findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                    findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                      findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                        findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                          findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                            findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                              findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                  findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                    findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                      findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                          findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                            findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                              findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  findmin(first=4, last=7) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    findmin(first=4, last=7) {