結果

問題 No.2221 Set X
ユーザー chineristACchineristAC
提出日時 2023-02-17 22:20:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,830 ms / 2,000 ms
コード長 1,242 bytes
コンパイル時間 721 ms
コンパイル使用メモリ 86,864 KB
実行使用メモリ 116,316 KB
最終ジャッジ日時 2023-09-26 19:36:40
合計ジャッジ時間 35,753 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
74,364 KB
testcase_01 AC 116 ms
74,440 KB
testcase_02 AC 115 ms
74,400 KB
testcase_03 AC 116 ms
74,224 KB
testcase_04 AC 114 ms
74,360 KB
testcase_05 AC 115 ms
74,132 KB
testcase_06 AC 114 ms
74,100 KB
testcase_07 AC 115 ms
74,504 KB
testcase_08 AC 125 ms
78,788 KB
testcase_09 AC 116 ms
74,456 KB
testcase_10 AC 128 ms
78,648 KB
testcase_11 AC 122 ms
78,724 KB
testcase_12 AC 123 ms
78,896 KB
testcase_13 AC 124 ms
79,044 KB
testcase_14 AC 129 ms
79,076 KB
testcase_15 AC 123 ms
78,736 KB
testcase_16 AC 509 ms
88,616 KB
testcase_17 AC 233 ms
83,492 KB
testcase_18 AC 492 ms
89,848 KB
testcase_19 AC 205 ms
83,256 KB
testcase_20 AC 347 ms
85,596 KB
testcase_21 AC 737 ms
94,516 KB
testcase_22 AC 1,049 ms
104,612 KB
testcase_23 AC 153 ms
81,732 KB
testcase_24 AC 674 ms
94,184 KB
testcase_25 AC 421 ms
91,380 KB
testcase_26 AC 1,401 ms
114,372 KB
testcase_27 AC 1,407 ms
114,364 KB
testcase_28 AC 1,406 ms
114,436 KB
testcase_29 AC 1,421 ms
116,316 KB
testcase_30 AC 1,345 ms
114,432 KB
testcase_31 AC 1,412 ms
114,484 KB
testcase_32 AC 1,485 ms
115,304 KB
testcase_33 AC 1,830 ms
115,308 KB
testcase_34 AC 1,631 ms
115,260 KB
testcase_35 AC 1,828 ms
115,128 KB
testcase_36 AC 1,416 ms
116,028 KB
testcase_37 AC 1,400 ms
114,656 KB
testcase_38 AC 1,756 ms
116,304 KB
testcase_39 AC 1,310 ms
111,196 KB
testcase_40 AC 1,574 ms
111,600 KB
testcase_41 AC 1,721 ms
115,388 KB
testcase_42 AC 1,681 ms
115,180 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
B = int((2*N)**.5)
for x in range(1,B):
    res = 1
    for i in range(1,N):
        if A[i]//x != A[i-1]//x:
            res += 1
    if res * (x+1) < min_val:
        arg_x,min_val = x,res*(x+1)

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(B,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