結果

問題 No.491 10^9+1と回文
ユーザー zimphazimpha
提出日時 2017-03-29 21:39:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 74 ms / 1,000 ms
コード長 2,789 bytes
コンパイル時間 2,479 ms
コンパイル使用メモリ 78,380 KB
実行使用メモリ 54,216 KB
最終ジャッジ日時 2024-04-08 16:27:44
合計ジャッジ時間 10,845 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
54,128 KB
testcase_01 AC 55 ms
54,076 KB
testcase_02 AC 54 ms
54,084 KB
testcase_03 AC 56 ms
54,108 KB
testcase_04 AC 58 ms
54,108 KB
testcase_05 AC 58 ms
54,112 KB
testcase_06 AC 56 ms
52,164 KB
testcase_07 AC 57 ms
54,088 KB
testcase_08 AC 57 ms
54,104 KB
testcase_09 AC 56 ms
54,112 KB
testcase_10 AC 56 ms
54,112 KB
testcase_11 AC 55 ms
54,104 KB
testcase_12 AC 56 ms
54,104 KB
testcase_13 AC 57 ms
54,096 KB
testcase_14 AC 56 ms
54,112 KB
testcase_15 AC 56 ms
54,124 KB
testcase_16 AC 57 ms
54,100 KB
testcase_17 AC 58 ms
54,100 KB
testcase_18 AC 57 ms
54,104 KB
testcase_19 AC 59 ms
54,112 KB
testcase_20 AC 56 ms
54,108 KB
testcase_21 AC 56 ms
54,100 KB
testcase_22 AC 56 ms
54,104 KB
testcase_23 AC 56 ms
54,076 KB
testcase_24 AC 56 ms
54,100 KB
testcase_25 AC 57 ms
54,100 KB
testcase_26 AC 55 ms
54,104 KB
testcase_27 AC 55 ms
54,120 KB
testcase_28 AC 55 ms
54,104 KB
testcase_29 AC 57 ms
54,088 KB
testcase_30 AC 56 ms
54,124 KB
testcase_31 AC 56 ms
54,108 KB
testcase_32 AC 57 ms
54,092 KB
testcase_33 AC 55 ms
54,100 KB
testcase_34 AC 55 ms
54,100 KB
testcase_35 AC 58 ms
54,116 KB
testcase_36 AC 55 ms
54,104 KB
testcase_37 AC 56 ms
54,092 KB
testcase_38 AC 55 ms
54,120 KB
testcase_39 AC 56 ms
54,120 KB
testcase_40 AC 55 ms
54,092 KB
testcase_41 AC 56 ms
54,104 KB
testcase_42 AC 56 ms
54,132 KB
testcase_43 AC 67 ms
54,064 KB
testcase_44 AC 58 ms
54,096 KB
testcase_45 AC 59 ms
54,068 KB
testcase_46 AC 58 ms
54,112 KB
testcase_47 AC 57 ms
54,092 KB
testcase_48 AC 55 ms
54,136 KB
testcase_49 AC 56 ms
54,116 KB
testcase_50 AC 56 ms
54,112 KB
testcase_51 AC 55 ms
54,112 KB
testcase_52 AC 54 ms
54,108 KB
testcase_53 AC 55 ms
52,088 KB
testcase_54 AC 55 ms
54,100 KB
testcase_55 AC 57 ms
54,080 KB
testcase_56 AC 55 ms
54,116 KB
testcase_57 AC 56 ms
54,216 KB
testcase_58 AC 56 ms
54,112 KB
testcase_59 AC 54 ms
54,116 KB
testcase_60 AC 54 ms
54,124 KB
testcase_61 AC 55 ms
54,096 KB
testcase_62 AC 74 ms
54,112 KB
testcase_63 AC 56 ms
54,108 KB
testcase_64 AC 56 ms
54,112 KB
testcase_65 AC 56 ms
54,068 KB
testcase_66 AC 56 ms
54,112 KB
testcase_67 AC 55 ms
54,116 KB
testcase_68 AC 55 ms
54,108 KB
testcase_69 AC 56 ms
54,116 KB
testcase_70 AC 58 ms
54,212 KB
testcase_71 AC 58 ms
54,204 KB
testcase_72 AC 58 ms
54,084 KB
testcase_73 AC 61 ms
54,104 KB
testcase_74 AC 56 ms
54,112 KB
testcase_75 AC 56 ms
54,088 KB
testcase_76 AC 56 ms
54,100 KB
testcase_77 AC 56 ms
54,112 KB
testcase_78 AC 55 ms
54,088 KB
testcase_79 AC 55 ms
54,080 KB
testcase_80 AC 55 ms
52,336 KB
testcase_81 AC 55 ms
54,100 KB
testcase_82 AC 56 ms
54,096 KB
testcase_83 AC 58 ms
54,072 KB
testcase_84 AC 57 ms
54,212 KB
testcase_85 AC 56 ms
54,068 KB
testcase_86 AC 55 ms
54,088 KB
testcase_87 AC 56 ms
54,120 KB
testcase_88 AC 55 ms
54,120 KB
testcase_89 AC 56 ms
54,068 KB
testcase_90 AC 70 ms
54,112 KB
testcase_91 AC 55 ms
54,088 KB
testcase_92 AC 58 ms
54,072 KB
testcase_93 AC 55 ms
54,104 KB
testcase_94 AC 55 ms
52,132 KB
testcase_95 AC 55 ms
52,372 KB
testcase_96 AC 58 ms
54,068 KB
testcase_97 AC 55 ms
54,140 KB
testcase_98 AC 55 ms
54,112 KB
testcase_99 AC 56 ms
52,156 KB
testcase_100 AC 55 ms
54,120 KB
testcase_101 AC 57 ms
54,112 KB
testcase_102 AC 55 ms
54,072 KB
testcase_103 AC 57 ms
54,100 KB
testcase_104 AC 56 ms
53,944 KB
testcase_105 AC 56 ms
54,208 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