結果
問題 | No.6 使いものにならないハッシュ |
ユーザー | fujisu |
提出日時 | 2015-02-02 23:24:54 |
言語 | Java21 (openjdk 21) |
結果 |
RE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,292 bytes |
コンパイル時間 | 2,397 ms |
コンパイル使用メモリ | 78,000 KB |
実行使用メモリ | 40,988 KB |
最終ジャッジ日時 | 2024-09-16 16:23:46 |
合計ジャッジ時間 | 6,714 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 64 ms
37,188 KB |
testcase_01 | AC | 58 ms
36,736 KB |
testcase_02 | AC | 113 ms
40,080 KB |
testcase_03 | AC | 84 ms
38,600 KB |
testcase_04 | AC | 89 ms
39,412 KB |
testcase_05 | AC | 96 ms
39,360 KB |
testcase_06 | AC | 109 ms
39,904 KB |
testcase_07 | AC | 93 ms
39,252 KB |
testcase_08 | AC | 106 ms
39,972 KB |
testcase_09 | AC | 86 ms
38,400 KB |
testcase_10 | RE | - |
testcase_11 | AC | 101 ms
38,836 KB |
testcase_12 | AC | 110 ms
39,580 KB |
testcase_13 | AC | 83 ms
38,304 KB |
testcase_14 | AC | 86 ms
38,528 KB |
testcase_15 | AC | 107 ms
39,572 KB |
testcase_16 | AC | 100 ms
39,280 KB |
testcase_17 | AC | 115 ms
39,672 KB |
testcase_18 | AC | 116 ms
39,500 KB |
testcase_19 | AC | 99 ms
39,844 KB |
testcase_20 | AC | 108 ms
39,860 KB |
testcase_21 | AC | 88 ms
37,832 KB |
testcase_22 | AC | 102 ms
39,532 KB |
testcase_23 | AC | 110 ms
39,528 KB |
testcase_24 | AC | 112 ms
39,884 KB |
testcase_25 | AC | 103 ms
39,916 KB |
testcase_26 | AC | 111 ms
39,744 KB |
testcase_27 | AC | 110 ms
39,796 KB |
testcase_28 | AC | 108 ms
40,988 KB |
testcase_29 | AC | 118 ms
40,176 KB |
testcase_30 | AC | 108 ms
40,040 KB |
testcase_31 | AC | 107 ms
39,448 KB |
ソースコード
import java.io.IOException; import java.util.Arrays; import java.util.InputMismatchException; import java.util.TreeSet; public class Main { int hash(int k) { if (k < 10) return k; int sum = 0; while (0 < k) { sum += k % 10; k /= 10; } return hash(sum); } void run() { MyScanner sc = new MyScanner(); int max = 200001; boolean[] prime = new boolean[max]; Arrays.fill(prime, true); prime[0] = prime[1] = false; for (int i = 0; i * i <= max; i++) { if (prime[i]) { for (int j = i * i; j < max; j += i) { prime[j] = false; } } } int n = sc.nextInt(); int m = sc.nextInt(); int count = 0; for (int i = n; i <= m; i++) { if (prime[i]) count++; } int[] list = new int[count]; int[] hash = new int[count]; int id = 0; for (int i = n; i <= m; i++) { if (prime[i]) { list[id] = i; hash[id] = hash(i); id++; } } int left = 0, right = 1; TreeSet<Integer> set = new TreeSet<Integer>(); int maxLength = 0; int maxNumber = 0; set.add(hash[left]); while (left < id) { if (id <= right || set.contains(hash[right])) { set.remove(hash[left++]); } else { set.add(hash[right++]); } if (maxLength <= right - left) { maxLength = right - left; maxNumber = list[left]; } } System.out.println(maxNumber); } public static void main(String[] args) { new Main().run(); } public void mapDebug(int[][] a) { System.out.println("--------map display---------"); for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[i].length; j++) { System.out.printf("%3d ", a[i][j]); } System.out.println(); } System.out.println("----------------------------" + '\n'); } class MyScanner { int read() { try { return System.in.read(); } catch (IOException e) { throw new InputMismatchException(); } } boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } boolean isEndline(int c) { return c == '\n' || c == '\r' || c == -1; } int nextInt() { return Integer.parseInt(next()); } int[] nextIntArray(int n) { int[] array = new int[n]; for (int i = 0; i < n; i++) array[i] = nextInt(); return array; } long nextLong() { return Long.parseLong(next()); } long[] nextLongArray(int n) { long[] array = new long[n]; for (int i = 0; i < n; i++) array[i] = nextLong(); return array; } double nextDouble() { return Double.parseDouble(next()); } double[] nextDoubleArray(int n) { double[] array = new double[n]; for (int i = 0; i < n; i++) array[i] = nextDouble(); return array; } String next() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } String[] nextStringArray(int n) { String[] array = new String[n]; for (int i = 0; i < n; i++) array[i] = next(); return array; } String nextLine() { int c = read(); while (isEndline(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndline(c)); return res.toString(); } } }