結果

問題 No.723 2つの数の和
ユーザー 👑 obakyan
提出日時 2019-04-28 17:53:36
言語 Lua
(LuaJit 2.1.1734355927)
結果
RE  
実行時間 -
コード長 627 bytes
コンパイル時間 105 ms
コンパイル使用メモリ 6,688 KB
実行使用メモリ 13,640 KB
最終ジャッジ日時 2024-12-17 15:55:06
合計ジャッジ時間 11,801 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14 RE * 5 TLE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

ior = io.read
local n, x = ior("*n", "*n")
local a = {}
for i = 1, n do a[i] = ior("*n") end
table.sort(a)
local left, right = 1, n
local cnt = 0
while(left <= right) do
  while(a[left] + a[right] < x) do
    left = left + 1
  end
  if(right < left) then
    break
  elseif(left == right and a[left] + a[right] == x) then
    cnt = cnt + 1
    break
  else
    if(a[left] + a[right] == x) then
      for tleft = left, right do
        if(a[tleft] + a[right] == x) then
          cnt = cnt + (tleft == right and 1 or 2)
        end
      end
      right = right - 1
    else
      right = right - 1
    end
  end
end
print(cnt)
0