結果

問題 No.528 10^9と10^9+7と回文
ユーザー maimai
提出日時 2017-06-10 23:02:51
言語 Ruby
(3.3.0)
結果
AC  
実行時間 86 ms / 1,000 ms
コード長 515 bytes
コンパイル時間 124 ms
コンパイル使用メモリ 11,536 KB
実行使用メモリ 16,448 KB
最終ジャッジ日時 2023-10-01 00:59:42
合計ジャッジ時間 3,654 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,164 KB
testcase_01 AC 80 ms
15,048 KB
testcase_02 AC 80 ms
15,052 KB
testcase_03 AC 81 ms
15,172 KB
testcase_04 AC 81 ms
15,172 KB
testcase_05 AC 81 ms
15,264 KB
testcase_06 AC 81 ms
15,260 KB
testcase_07 AC 82 ms
15,044 KB
testcase_08 AC 82 ms
15,272 KB
testcase_09 AC 81 ms
15,276 KB
testcase_10 AC 83 ms
16,312 KB
testcase_11 AC 86 ms
16,192 KB
testcase_12 AC 86 ms
16,216 KB
testcase_13 AC 86 ms
16,312 KB
testcase_14 AC 84 ms
16,028 KB
testcase_15 AC 82 ms
16,036 KB
testcase_16 AC 81 ms
16,140 KB
testcase_17 AC 83 ms
15,800 KB
testcase_18 AC 85 ms
16,320 KB
testcase_19 AC 80 ms
15,756 KB
testcase_20 AC 81 ms
15,960 KB
testcase_21 AC 80 ms
15,956 KB
testcase_22 AC 79 ms
15,048 KB
testcase_23 AC 79 ms
15,244 KB
testcase_24 AC 83 ms
15,328 KB
testcase_25 AC 82 ms
15,680 KB
testcase_26 AC 85 ms
16,412 KB
testcase_27 AC 84 ms
16,448 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def ascan; gets.split.map(&:to_i); end
def scan; gets.to_i; end

nstr = gets.chomp

def solve(nstr, md)
    sz = nstr.size
    # 上位半分
    r = nstr[0..((sz+1)/2-1)].to_i
    # 下半分なら999...通りぐらいある
    r+= 10**(sz/2) - 1
    # 下半分の回文ができない
    r-=1 if nstr[0..(sz/2-1)].reverse > nstr[((sz+1)/2)..-1]
    return r%md
end

if nstr.size == 1
    p nstr.to_i, nstr.to_i
else
    p solve(nstr,(1e9).to_i)
    p solve(nstr,(1e9+7).to_i)
end

# 参考: submissions/179227
0