結果
問題 | No.319 happy b1rthday 2 me |
ユーザー | Grenache |
提出日時 | 2015-12-12 20:41:37 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,911 bytes |
コンパイル時間 | 3,682 ms |
コンパイル使用メモリ | 79,576 KB |
実行使用メモリ | 50,568 KB |
最終ジャッジ日時 | 2024-09-15 08:47:43 |
合計ジャッジ時間 | 6,434 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
37,248 KB |
testcase_01 | AC | 53 ms
36,992 KB |
testcase_02 | AC | 54 ms
36,960 KB |
testcase_03 | AC | 53 ms
37,120 KB |
testcase_04 | AC | 53 ms
37,120 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 54 ms
37,120 KB |
testcase_08 | AC | 54 ms
37,280 KB |
testcase_09 | AC | 54 ms
37,008 KB |
testcase_10 | AC | 53 ms
36,904 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 53 ms
36,744 KB |
testcase_15 | AC | 53 ms
36,772 KB |
testcase_16 | AC | 52 ms
36,820 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 53 ms
37,152 KB |
testcase_21 | AC | 53 ms
37,280 KB |
testcase_22 | AC | 53 ms
36,712 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 53 ms
37,096 KB |
testcase_27 | WA | - |
testcase_28 | AC | 53 ms
36,948 KB |
testcase_29 | AC | 53 ms
37,120 KB |
testcase_30 | AC | 54 ms
37,008 KB |
testcase_31 | AC | 53 ms
37,052 KB |
testcase_32 | WA | - |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.Map; import java.util.PriorityQueue; public class Main_yukicoder319 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); long a = sc.nextLong(); long b = sc.nextLong(); pr.println(happy(b) - happy(a - 1)); // for (long aa = 1; aa < 10000; aa++) { // pr.printf("%d : %d\n", aa, happy(aa)); // } pr.close(); sc.close(); } private static long happy(long a) { long base = 1; long n12 = 12; long ret = 0; while (a > base) { long tmp1 = a / (base * 100); long tmp2 = a % (base * 100); ret += tmp1 * base; long tmp3 = tmp2 - base * n12 + 1; tmp3 = Math.max(tmp3, 0); tmp3 = Math.min(tmp3, base); ret += tmp3; base *= 10; } if (a >= 22) { String s = Long.toString(a); int n = s.length(); if (n <= 2) { ret += 1; } else { int d1 = s.charAt(n - 1) - '0'; int d2 = s.charAt(0) - '0'; char[] tmp = s.substring(1, n - 1).toCharArray(); long b = 1; for (int i = 0; i < n - 2; i++) { ret += b; b *= 10; } if (d2 == 2) { long tmp1 = Long.parseLong(new String(tmp)); // long tmp1 = 0; // long b2 = 1; // for (int i = tmp.length - 1; i >= 0; i--) { // tmp1 += (tmp[i] - '0' + 1) * b2; // b2 *= 10; // } ret += tmp1 + 1; if (d1 < 2) { ret--; } } else if (d2 > 2) { ret += b; } else { } } } return ret; } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator<String> it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { it = Arrays.asList(br.readLine().split(" ")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }