結果

問題 No.831 都市めぐり
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-09 22:24:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 506 ms / 2,000 ms
コード長 470 bytes
コンパイル時間 78 ms
コンパイル使用メモリ 11,956 KB
実行使用メモリ 10,176 KB
最終ジャッジ日時 2023-10-19 08:48:50
合計ジャッジ時間 3,412 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,176 KB
testcase_01 AC 32 ms
10,176 KB
testcase_02 AC 33 ms
10,176 KB
testcase_03 AC 32 ms
10,176 KB
testcase_04 AC 31 ms
10,176 KB
testcase_05 AC 30 ms
10,176 KB
testcase_06 AC 30 ms
10,176 KB
testcase_07 AC 30 ms
10,176 KB
testcase_08 AC 33 ms
10,176 KB
testcase_09 AC 30 ms
10,176 KB
testcase_10 AC 32 ms
10,176 KB
testcase_11 AC 32 ms
10,176 KB
testcase_12 AC 56 ms
10,176 KB
testcase_13 AC 50 ms
10,176 KB
testcase_14 AC 54 ms
10,176 KB
testcase_15 AC 229 ms
10,176 KB
testcase_16 AC 114 ms
10,176 KB
testcase_17 AC 274 ms
10,176 KB
testcase_18 AC 338 ms
10,176 KB
testcase_19 AC 484 ms
10,176 KB
testcase_20 AC 506 ms
10,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
if n == 1:
    print(0)
    exit()

if n % 2 == 0:
    cost = 0
    m = n // 2
    for i in range(1, m):
        cost += i * (n - i)
    for i in range(2, m + 1):
        cost += i * (n - i + 2)
    cost += 1 * n
    cost += m * (m + 1)
else:
    cost = 0
    m = n // 2 + 1
    for i in range(1, m - 1):
        cost += i * (n - i)
    for i in range(2, m):
        cost += i * (n - i + 2)
    cost += 1 * n
    cost += m * (m - 1 + m + 1)

print(cost)
0