結果

問題 No.491 10^9+1と回文
ユーザー nebukuro09
提出日時 2017-03-10 23:54:04
言語 D
(dmd 2.109.1)
結果
TLE  
実行時間 -
コード長 1,104 bytes
コンパイル時間 1,409 ms
コンパイル使用メモリ 148,896 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-06-12 18:20:19
合計ジャッジ時間 5,401 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other WA * 2 TLE * 2 -- * 99
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

bool is_kaibun(string s) {
    int n = s.length.to!int;
    foreach (i; 0..n/2) {
        if (s[i] != s[n-i-1]) return false;
    }
    return true;
}

void main() {
    long N = readln.chomp.to!long;
    long M = 10^^9;
    long a = N / M;
    if (a == 0) {
        writeln(0);
        return;
    }
    string s = a.to!string;
    long b = s.length;

    long ans = 0;
    foreach (i; 1..b+1) {
        if (i == b) {
            ans += 10 ^^ (i/2+i%2-1) * (s[0].to!string.to!long-1);
        }
        else {
            if (i == 1)
                ans += 9;
            else
                ans += 10^^(i/2+i%2);
        }
    }

    long keta = b-1;
    long base = a - (a % 10^^(b-1));
    foreach (i; 0..10^^keta) {
        long nnn;
        nnn = base + i;
        if (!(is_kaibun(nnn.to!string))) continue;
        long mmm = nnn*10^^9 + nnn;
        if (mmm <= N) ans++;

    }

    ans.writeln;
}
0