結果

問題 No.71 そろばん
ユーザー kichirb3
提出日時 2018-03-26 21:03:46
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 959 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-06-25 07:25:42
合計ジャッジ時間 1,830 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
"""
No.71 そろばん
https://yukicoder.me/problems/no/71

"""
import sys
from sys import stdin
input = stdin.readline


def calc_max(N, x):
    # 下段の珠の数をx個にした場合に表現できる最大数
    return -(x*x) + N*x + N

def solve(N):
    #  下段の珠の数を求める
    ub = N
    lb = 1

    while True:
        mid1 = (lb*2 + ub) // 3
        mid2 = (lb + ub*2) // 3
        mid1_score = calc_max(N, mid1)
        mid2_score = calc_max(N, mid2)
        if mid2_score < mid1_score:
            ub = mid2
        else:
            lb = mid1
        if ub - lb <= 4:
            break
    
    # 下段の珠の数をlb〜ub全てでチェックして、最大値を求める        
    ans = 0
    for i in range(lb, ub+1):
        ans = max(ans, calc_max(N, i))
    return ans


def main(args):
    N = int(input())
    ans = solve(N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
0