結果
| 問題 | No.491 10^9+1と回文 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-03-10 23:50:19 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,130 bytes |
| 記録 | |
| コンパイル時間 | 1,388 ms |
| コンパイル使用メモリ | 146,692 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-12 18:19:50 |
| 合計ジャッジ時間 | 3,292 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 43 WA * 60 |
ソースコード
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;
keta = keta/2+keta%2;
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;
}