結果

問題 No.1185 完全な3の倍数
コンテスト
ユーザー 萩3
提出日時 2021-05-03 12:57:15
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 588 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 552 ms
コンパイル使用メモリ 20,824 KB
実行使用メモリ 15,488 KB
最終ジャッジ日時 2026-04-03 07:05:42
合計ジャッジ時間 8,832 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import math
import sys

def resolve():
    nstr = input()
    length = len(nstr)
    n = int(nstr)

    if length == 2:
        print(n//3-3)
        return

    result = 30
    
    if length - 3 > 0:
        result += 16*(4**(length-3)-1)

    head = int(nstr[0])
    result += (head-1)//3 * 4**(length-1)
    if head%3 != 0:
        print(result)
        return

    for i, c in zip(range(length-1,0,-1),nstr[1:]):
        if int(c) == 0: continue
        result += (int(c)+2)//3 * 4**(i-1)

        if int(c)%3 != 0: break

    else:
        result += 1

    print(result)

resolve()
0