結果

問題 No.1884 Sequence
ユーザー 👑 obakyan
提出日時 2022-03-29 19:58:53
言語 Lua
(LuaJit 2.1.1734355927)
結果
AC  
実行時間 214 ms / 2,000 ms
コード長 821 bytes
コンパイル時間 553 ms
コンパイル使用メモリ 5,248 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-08 18:03:08
合計ジャッジ時間 9,740 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

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