結果
問題 | No.491 10^9+1と回文 |
ユーザー |
|
提出日時 | 2017-03-11 00:04:38 |
言語 | D (dmd 2.109.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,335 bytes |
コンパイル時間 | 1,017 ms |
コンパイル使用メモリ | 116,820 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-12 18:21:07 |
合計ジャッジ時間 | 4,962 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 WA * 63 |
ソースコード
import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm; import std.uni, std.math, std.container, std.typecons, std.typetuple; import core.bitop, std.datetime; void main(){ auto N = readln.chomp.to!ulong; ulong a = 10^^9 + 1; ulong M = N / a; ulong ans; //stderr.writeln(M); ulong[10] k = [0, 9, 9, 90, 90, 900, 900, 9000, 9000, 90000]; //stderr.writeln(k); int d = 1; while(10^^d <= M){ ans += k[d]; ++d; } --d; //stderr.writeln(d); int uni = d > 0 ? 10^^d + 1 : 1; int e = 1; while(uni*e <= M){ //stderr.writeln(uni*e); ans += max(1, k[max(0, d - 2)]); ++e; } --e; //stderr.writeln(e); int f = 1; while(uni*e + f*10 <= M){ if(is_kaibun(f)){ ++ans; } ++f; } writeln(ans); } bool is_kaibun(int m){ int rev, rem, tmp; tmp = m; while(tmp != 0){ rem = tmp % 10; rev = rev * 10 + rem; tmp /= 10; } if(m == rev) return true; else return false; } void readVars(T...)(auto ref T args){ auto line = readln.split; foreach(ref arg ; args){ arg = line.front.to!(typeof(arg)); line.popFront; } if(!line.empty){ throw new Exception("args num < input num"); } }