結果

問題 No.71 そろばん
ユーザー kichirb3kichirb3
提出日時 2018-03-26 21:03:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 959 bytes
コンパイル時間 670 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 8,000 KB
最終ジャッジ日時 2023-09-07 13:19:05
合計ジャッジ時間 2,458 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,740 KB
testcase_01 AC 16 ms
7,956 KB
testcase_02 AC 16 ms
7,808 KB
testcase_03 AC 16 ms
7,820 KB
testcase_04 AC 16 ms
8,000 KB
testcase_05 AC 16 ms
7,868 KB
testcase_06 AC 16 ms
7,816 KB
testcase_07 AC 16 ms
7,976 KB
testcase_08 AC 16 ms
7,852 KB
testcase_09 AC 16 ms
7,828 KB
testcase_10 AC 16 ms
7,864 KB
testcase_11 AC 16 ms
7,960 KB
testcase_12 AC 16 ms
7,900 KB
testcase_13 AC 16 ms
7,792 KB
testcase_14 AC 16 ms
7,952 KB
testcase_15 AC 16 ms
7,800 KB
testcase_16 AC 16 ms
7,740 KB
testcase_17 AC 16 ms
7,816 KB
testcase_18 AC 16 ms
7,880 KB
testcase_19 AC 16 ms
7,796 KB
testcase_20 AC 17 ms
7,972 KB
testcase_21 AC 15 ms
7,880 KB
testcase_22 AC 16 ms
7,944 KB
権限があれば一括ダウンロードができます

ソースコード

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