結果

問題 No.1884 Sequence
ユーザー 👑 obakyanobakyan
提出日時 2022-03-29 19:58:53
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 214 ms / 2,000 ms
コード長 821 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 5,248 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 05:20:31
合計ジャッジ時間 8,383 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 213 ms
5,376 KB
testcase_11 AC 208 ms
5,376 KB
testcase_12 AC 141 ms
5,376 KB
testcase_13 AC 154 ms
5,376 KB
testcase_14 AC 136 ms
5,376 KB
testcase_15 AC 200 ms
5,376 KB
testcase_16 AC 205 ms
5,376 KB
testcase_17 AC 196 ms
5,376 KB
testcase_18 AC 170 ms
5,376 KB
testcase_19 AC 176 ms
5,376 KB
testcase_20 AC 193 ms
5,376 KB
testcase_21 AC 185 ms
5,376 KB
testcase_22 AC 194 ms
5,376 KB
testcase_23 AC 214 ms
5,376 KB
testcase_24 AC 207 ms
5,376 KB
testcase_25 AC 201 ms
5,376 KB
testcase_26 AC 207 ms
5,376 KB
testcase_27 AC 176 ms
5,376 KB
testcase_28 AC 173 ms
5,376 KB
testcase_29 AC 173 ms
5,376 KB
testcase_30 AC 178 ms
5,376 KB
testcase_31 AC 156 ms
5,376 KB
testcase_32 AC 209 ms
5,376 KB
testcase_33 AC 178 ms
5,376 KB
testcase_34 AC 178 ms
5,376 KB
testcase_35 AC 177 ms
5,376 KB
testcase_36 AC 181 ms
5,376 KB
testcase_37 AC 173 ms
5,376 KB
testcase_38 AC 176 ms
5,376 KB
testcase_39 AC 180 ms
5,376 KB
testcase_40 AC 180 ms
5,376 KB
testcase_41 AC 202 ms
5,376 KB
testcase_42 AC 200 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mfl, mce = math.floor, math.ceil
local function getgcd(x, y)
  while 0 < x do
    x, y = y % x, x
  end
  return y
end

local n = io.read("*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
table.sort(a, function(x, y) return x > y end)
for i = n, 1, -1 do
  if a[i] == 0 then table.remove(a) else break end
end
local zeros = n - #a
n = #a
if n <= 2 then print("Yes") os.exit() end
local same, allsame = false, true
for i = 1, n - 1 do
  if a[i] == a[i + 1] then
    same = true
  else
    allsame = false
  end
end
if allsame then print("Yes") os.exit() end
if same then print("No") os.exit() end
local gcd = a[1] - a[2]
for i = 2, n - 1 do
  gcd = getgcd(gcd, a[i] - a[i + 1])
end
local len = mfl((a[1] - a[n]) / gcd)
local need = len + 1 - n
if need <= zeros then
  print("Yes")
else
  print("No")
end
0