fork(4) download
  1. package gcj2013.template;
  2.  
  3. import java.io.*;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import java.util.Scanner;
  7. import java.util.concurrent.Callable;
  8. import java.util.concurrent.ExecutorService;
  9. import java.util.concurrent.Executors;
  10. import java.util.concurrent.Future;
  11.  
  12. import static java.util.Arrays.deepToString;
  13.  
  14. public class Template2 implements Runnable {
  15. private static final char PROB = Template2.class.getSimpleName().charAt(0);
  16. private static int DEFAULT_PARARELL = Runtime.getRuntime().availableProcessors() + 1;
  17. private static File DIR = new File(".");
  18. private static boolean TEST_ALL = false;
  19.  
  20. public static class Solver implements Callable<String> {
  21. private static final double EPS = 1e-12;
  22. private static final int INF = 1 << 20;
  23. private static final int[] di = { -1, 0, 0, 1 };
  24. private static final int[] dj = { 0, -1, 1, 0 };
  25.  
  26. // shared table
  27. static {
  28. // :TODO
  29. }
  30.  
  31. // parse
  32. public Solver(final Scanner sc) {
  33. // :TODO
  34. }
  35.  
  36. // solve
  37. @Override
  38. public String call() {
  39. // :TODO
  40. throw null;
  41. }
  42. }
  43.  
  44. // Template
  45. @Override
  46. public void run() {
  47. final ExecutorService es = Executors.newFixedThreadPool(DEFAULT_PARARELL);
  48. try (final Scanner sc = new Scanner(System.in)) {
  49. final List<Future<String>> list = new ArrayList<>();
  50. final int T = sc.nextInt();
  51. for (int i = 0; i < T; i++)
  52. list.add(es.submit(new Solver(sc)));
  53. for (int t = 1; t <= T; t++) {
  54. debugf("Case #%s%n", t);
  55. System.out.printf("Case #%s: %s%n", t, list.get(t - 1).get());
  56. System.gc();
  57. }
  58. debug("done.");
  59. } catch (Exception e) {
  60. e.printStackTrace();
  61. }
  62. es.shutdown();
  63. }
  64.  
  65. public static void main(String... args) throws IOException {
  66. if (TEST_ALL) {
  67. for (final String input : seekInputFiles()) {
  68. debug("INPUT", input);
  69. System.setIn(new BufferedInputStream(new FileInputStream(new File(DIR, input))));
  70. System.setOut(new PrintStream(input + ".out"));
  71. new Template2().run();
  72. }
  73. } else {
  74. final String input = seekInputFile();
  75. debug("INPUT", input);
  76. if (input != null) {
  77. System.setIn(new BufferedInputStream(new FileInputStream(new File(DIR, input))));
  78. System.setOut(new PrintStream(input + ".out"));
  79. } else
  80. DEFAULT_PARARELL = 1;
  81. new Template2().run();
  82. }
  83. }
  84.  
  85. private static String seekInputFile() {
  86. final String[] names = new String[] { PROB + "-large-practice-2.in", PROB + "-large-practice-1.in",
  87. PROB + "-large-practice.in", PROB + "-large-2.in", PROB + "-large-1.in", PROB + "-large.in",
  88. PROB + "-small-practice-2.in", PROB + "-small-practice-1.in", PROB + "-small-practice.in" };
  89. for (final String s : names)
  90. if (new File(DIR, s).exists())
  91. return s;
  92. for (int k = 2; k >= 0; k--) {
  93. int max = -1;
  94. for (int i = 0; new File(DIR, PROB + "-small" + (k > 0 ? "-" + k : "") + "-attempt" + i + ".in").exists(); i++)
  95. max = i;
  96. if (max >= 0)
  97. return PROB + "-small" + (k > 0 ? "-" + k : "") + "-attempt" + max + ".in";
  98. }
  99. return null;
  100. }
  101.  
  102. private static List<String> seekInputFiles() {
  103. final List<String> ret = new ArrayList<>();
  104. final String[] names = new String[] { PROB + "-large-practice-2.in", PROB + "-large-practice-1.in",
  105. PROB + "-large-practice.in", PROB + "-large-2.in", PROB + "-large-1.in", PROB + "-large.in",
  106. PROB + "-small-practice-2.in", PROB + "-small-practice-1.in", PROB + "-small-practice.in" };
  107. for (final String s : names)
  108. if (new File(DIR, s).exists())
  109. ret.add(s);
  110. for (int k = 2; k >= 0; k--) {
  111. int max = -1;
  112. for (int i = 0; new File(DIR, PROB + "-small" + (k > 0 ? "-" + k : "") + "-attempt" + i + ".in").exists(); i++)
  113. max = i;
  114. if (max >= 0)
  115. ret.add(PROB + "-small" + (k > 0 ? "-" + k : "") + "-attempt" + max + ".in");
  116. }
  117. return ret;
  118. }
  119.  
  120. private static void debugf(String format, Object... os) {
  121. System.err.printf(format, os);
  122. }
  123.  
  124. private static void debug(Object... os) {
  125. System.err.println(deepToString(os));
  126. }
  127. }
  128.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty