結果

問題 No.2221 Set X
ユーザー chineristACchineristAC
提出日時 2023-02-17 22:24:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 361 ms / 2,000 ms
コード長 1,045 bytes
コンパイル時間 398 ms
コンパイル使用メモリ 86,872 KB
実行使用メモリ 120,048 KB
最終ジャッジ日時 2023-09-26 19:39:48
合計ジャッジ時間 10,374 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
74,464 KB
testcase_01 AC 114 ms
74,356 KB
testcase_02 AC 115 ms
74,392 KB
testcase_03 AC 114 ms
74,464 KB
testcase_04 AC 114 ms
74,428 KB
testcase_05 AC 115 ms
74,460 KB
testcase_06 AC 116 ms
74,148 KB
testcase_07 AC 115 ms
74,436 KB
testcase_08 AC 121 ms
73,996 KB
testcase_09 AC 116 ms
74,460 KB
testcase_10 AC 122 ms
78,876 KB
testcase_11 AC 117 ms
74,472 KB
testcase_12 AC 115 ms
74,468 KB
testcase_13 AC 119 ms
74,044 KB
testcase_14 AC 120 ms
78,588 KB
testcase_15 AC 119 ms
74,472 KB
testcase_16 AC 195 ms
92,840 KB
testcase_17 AC 161 ms
83,352 KB
testcase_18 AC 200 ms
94,956 KB
testcase_19 AC 157 ms
83,348 KB
testcase_20 AC 180 ms
88,944 KB
testcase_21 AC 261 ms
102,180 KB
testcase_22 AC 317 ms
111,272 KB
testcase_23 AC 135 ms
81,044 KB
testcase_24 AC 260 ms
102,280 KB
testcase_25 AC 209 ms
91,312 KB
testcase_26 AC 195 ms
109,664 KB
testcase_27 AC 203 ms
113,708 KB
testcase_28 AC 201 ms
113,572 KB
testcase_29 AC 210 ms
114,740 KB
testcase_30 AC 206 ms
114,712 KB
testcase_31 AC 209 ms
114,220 KB
testcase_32 AC 266 ms
114,516 KB
testcase_33 AC 361 ms
114,288 KB
testcase_34 AC 342 ms
114,544 KB
testcase_35 AC 314 ms
114,588 KB
testcase_36 AC 206 ms
114,576 KB
testcase_37 AC 206 ms
114,580 KB
testcase_38 AC 208 ms
114,920 KB
testcase_39 AC 267 ms
120,048 KB
testcase_40 AC 279 ms
110,284 KB
testcase_41 AC 259 ms
114,060 KB
testcase_42 AC 257 ms
113,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import gcd,log

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

N = int(input())
A = li()


arg_x = 1
min_val = 2*N

plus = set([i for i in range(N)])
minus = set([i for i in range(N)])
diff = [(A[i+1]-A[i],i) for i in range(N-1)]
diff.sort(reverse=True)
for x in range(1,2*N+1):
    """
    種類数は [2N/(x+1)] 以下
    → A_i-A_{i-1} >= x が成り立つiは [2N/(x+1)]個以下
    """
    while diff and diff[-1][0] <= x:
        d,i = diff.pop()
        plus.remove(i)
        minus.remove(i+1)
    #print(x,plus,minus)
    if len(plus) * (x+1) < min_val:
        tmp = 0
        for i in plus:
            tmp += A[i]//x
        for i in minus:
            tmp -= A[i]//x
        tmp += len(plus)
        tmp *= (x+1)
        if tmp < min_val:
            arg_x,min_val = x,tmp


print(arg_x)
print(min_val)
        
0