結果

問題 No.1083 余りの余り
ユーザー FromBooskaFromBooska
提出日時 2023-02-14 19:15:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 245 ms / 3,000 ms
コード長 894 bytes
コンパイル時間 1,352 ms
コンパイル使用メモリ 86,932 KB
実行使用メモリ 77,164 KB
最終ジャッジ日時 2023-09-24 07:25:49
合計ジャッジ時間 7,279 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,172 KB
testcase_01 AC 73 ms
71,320 KB
testcase_02 AC 74 ms
71,412 KB
testcase_03 AC 74 ms
71,148 KB
testcase_04 AC 82 ms
76,556 KB
testcase_05 AC 122 ms
76,240 KB
testcase_06 AC 73 ms
71,504 KB
testcase_07 AC 80 ms
76,376 KB
testcase_08 AC 72 ms
71,500 KB
testcase_09 AC 72 ms
71,464 KB
testcase_10 AC 73 ms
71,532 KB
testcase_11 AC 79 ms
76,576 KB
testcase_12 AC 72 ms
71,224 KB
testcase_13 AC 73 ms
71,532 KB
testcase_14 AC 73 ms
71,276 KB
testcase_15 AC 73 ms
71,560 KB
testcase_16 AC 72 ms
71,216 KB
testcase_17 AC 71 ms
71,372 KB
testcase_18 AC 156 ms
76,636 KB
testcase_19 AC 121 ms
76,520 KB
testcase_20 AC 78 ms
76,632 KB
testcase_21 AC 83 ms
76,368 KB
testcase_22 AC 72 ms
71,372 KB
testcase_23 AC 244 ms
76,988 KB
testcase_24 AC 244 ms
76,892 KB
testcase_25 AC 245 ms
77,048 KB
testcase_26 AC 243 ms
77,164 KB
testcase_27 AC 72 ms
71,324 KB
testcase_28 AC 243 ms
77,096 KB
testcase_29 AC 72 ms
71,288 KB
testcase_30 AC 71 ms
71,364 KB
testcase_31 AC 73 ms
71,288 KB
testcase_32 AC 75 ms
71,416 KB
testcase_33 AC 82 ms
76,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# Aの最小値未満の整数値で一番大きい数字になるmodで最初に割る、それがキープされる
# というのでは不足
# Ai < AjのときK mod Ai mod Aj = K mod Ai
# だがK mod Aj mod Ai は K mod Ai nor K mod Aj
# つまりAを降順に並べたとき、大きいほうから使うか使わないかの2択がある
# それをビット全探索する、しかし最後はmod Aminが必要
# また、Ai=Ajならば1つだけでいい

N, K = map(int, input().split())
A = list(map(int, input().split()))
A_set = set(A)
A_list = list(A_set)
A_sorted = sorted(A_list, reverse = True)
A_bruteforce = A_sorted[:-1]

ans = 0
for bit in range(1<<len(A_bruteforce)):
    k = K
    for shift in range(len(A_bruteforce)):
        if bit>>shift & 1 == 1:
            k %= A_bruteforce[shift]
    k %= A_sorted[-1]
    ans = max(ans, k)
    #print(bin(bit), k)
print(ans)




0