結果

問題 No.491 10^9+1と回文
ユーザー zimphazimpha
提出日時 2017-03-29 21:39:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 55 ms / 1,000 ms
コード長 2,789 bytes
コンパイル時間 2,203 ms
コンパイル使用メモリ 78,848 KB
実行使用メモリ 37,372 KB
最終ジャッジ日時 2024-10-01 08:40:41
合計ジャッジ時間 10,163 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
36,992 KB
testcase_01 AC 51 ms
37,208 KB
testcase_02 AC 50 ms
36,888 KB
testcase_03 AC 48 ms
37,144 KB
testcase_04 AC 49 ms
37,012 KB
testcase_05 AC 48 ms
37,192 KB
testcase_06 AC 50 ms
36,968 KB
testcase_07 AC 48 ms
37,056 KB
testcase_08 AC 50 ms
37,228 KB
testcase_09 AC 50 ms
36,688 KB
testcase_10 AC 47 ms
36,812 KB
testcase_11 AC 49 ms
37,204 KB
testcase_12 AC 50 ms
37,116 KB
testcase_13 AC 49 ms
36,892 KB
testcase_14 AC 48 ms
37,032 KB
testcase_15 AC 49 ms
36,684 KB
testcase_16 AC 54 ms
37,044 KB
testcase_17 AC 53 ms
37,028 KB
testcase_18 AC 50 ms
36,836 KB
testcase_19 AC 51 ms
37,012 KB
testcase_20 AC 53 ms
36,912 KB
testcase_21 AC 52 ms
37,116 KB
testcase_22 AC 50 ms
37,012 KB
testcase_23 AC 49 ms
37,072 KB
testcase_24 AC 48 ms
37,120 KB
testcase_25 AC 49 ms
36,792 KB
testcase_26 AC 49 ms
37,244 KB
testcase_27 AC 48 ms
36,928 KB
testcase_28 AC 48 ms
37,228 KB
testcase_29 AC 48 ms
37,020 KB
testcase_30 AC 49 ms
36,848 KB
testcase_31 AC 49 ms
37,016 KB
testcase_32 AC 50 ms
37,232 KB
testcase_33 AC 53 ms
36,884 KB
testcase_34 AC 49 ms
37,140 KB
testcase_35 AC 50 ms
37,092 KB
testcase_36 AC 48 ms
37,004 KB
testcase_37 AC 50 ms
37,068 KB
testcase_38 AC 48 ms
37,192 KB
testcase_39 AC 49 ms
37,180 KB
testcase_40 AC 50 ms
37,284 KB
testcase_41 AC 50 ms
37,244 KB
testcase_42 AC 50 ms
37,092 KB
testcase_43 AC 49 ms
36,844 KB
testcase_44 AC 50 ms
37,072 KB
testcase_45 AC 51 ms
37,228 KB
testcase_46 AC 50 ms
37,068 KB
testcase_47 AC 50 ms
36,884 KB
testcase_48 AC 49 ms
37,048 KB
testcase_49 AC 48 ms
37,072 KB
testcase_50 AC 49 ms
37,192 KB
testcase_51 AC 51 ms
37,204 KB
testcase_52 AC 49 ms
36,648 KB
testcase_53 AC 49 ms
37,372 KB
testcase_54 AC 50 ms
36,584 KB
testcase_55 AC 49 ms
37,008 KB
testcase_56 AC 51 ms
36,916 KB
testcase_57 AC 50 ms
36,940 KB
testcase_58 AC 51 ms
36,876 KB
testcase_59 AC 51 ms
36,920 KB
testcase_60 AC 51 ms
37,184 KB
testcase_61 AC 51 ms
36,508 KB
testcase_62 AC 50 ms
36,860 KB
testcase_63 AC 50 ms
37,000 KB
testcase_64 AC 51 ms
37,244 KB
testcase_65 AC 51 ms
36,680 KB
testcase_66 AC 53 ms
37,044 KB
testcase_67 AC 53 ms
37,236 KB
testcase_68 AC 51 ms
37,116 KB
testcase_69 AC 53 ms
37,056 KB
testcase_70 AC 51 ms
37,072 KB
testcase_71 AC 52 ms
37,068 KB
testcase_72 AC 52 ms
37,136 KB
testcase_73 AC 53 ms
36,996 KB
testcase_74 AC 52 ms
37,152 KB
testcase_75 AC 52 ms
37,244 KB
testcase_76 AC 53 ms
36,900 KB
testcase_77 AC 53 ms
37,072 KB
testcase_78 AC 52 ms
37,212 KB
testcase_79 AC 53 ms
36,916 KB
testcase_80 AC 52 ms
36,796 KB
testcase_81 AC 54 ms
37,072 KB
testcase_82 AC 54 ms
36,988 KB
testcase_83 AC 53 ms
36,832 KB
testcase_84 AC 53 ms
36,888 KB
testcase_85 AC 53 ms
37,016 KB
testcase_86 AC 51 ms
36,860 KB
testcase_87 AC 50 ms
37,060 KB
testcase_88 AC 50 ms
37,232 KB
testcase_89 AC 50 ms
36,584 KB
testcase_90 AC 53 ms
36,892 KB
testcase_91 AC 51 ms
36,824 KB
testcase_92 AC 54 ms
36,836 KB
testcase_93 AC 53 ms
37,140 KB
testcase_94 AC 54 ms
37,064 KB
testcase_95 AC 54 ms
37,184 KB
testcase_96 AC 54 ms
37,132 KB
testcase_97 AC 52 ms
36,912 KB
testcase_98 AC 51 ms
37,128 KB
testcase_99 AC 52 ms
37,048 KB
testcase_100 AC 53 ms
36,928 KB
testcase_101 AC 55 ms
36,872 KB
testcase_102 AC 55 ms
37,148 KB
testcase_103 AC 54 ms
37,200 KB
testcase_104 AC 54 ms
37,124 KB
testcase_105 AC 54 ms
37,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Chiaki.Hoshinomori
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task491 solver = new Task491();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task491 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextLong();
            n = n / 1000000001;
            if (n == 0) {
                out.println(0);
            } else {
                int ret = 0;
                char[] s = new Long(n).toString().toCharArray();
                int[] pw = new int[10];
                pw[0] = 1;
                for (int i = 1; i < 10; i++) {
                    pw[i] = pw[i - 1] * 10;
                }
                for (int i = 1; i < s.length; ++i) {
                    ret += 9 * pw[(i + 1) / 2 - 1];
                }
                int now = 0;
                for (int i = 0; i < (s.length + 1) / 2; i++) {
                    now = now * 10 + s[i] - '0';
                    int coef = s[i] - '0';
                    int rest = (s.length + 1) / 2 - (i + 1);
                    if (i == 0) --coef;
                    ret += coef * pw[rest];
                }
                now *= pw[s.length - (s.length + 1) / 2];
                for (int i = 0; i < s.length - (s.length + 1) / 2; ++i) {
                    now += pw[i] * (s[i] - '0');
                }
                if (now <= n) ++ret;
                out.println(ret);
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

0