結果
問題 |
No.723 2つの数の和
|
ユーザー |
👑 |
提出日時 | 2019-04-28 18:51:03 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 62 ms / 2,000 ms |
コード長 | 974 bytes |
コンパイル時間 | 472 ms |
コンパイル使用メモリ | 6,952 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-17 18:19:01 |
合計ジャッジ時間 | 2,074 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
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(left <= right and 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 if(a[left] == a[right]) then cnt = cnt + (right - left + 1) * (right - left + 1) break else local lcnt, rcnt = 1, 1 for tleft = left + 1, right - 1 do if(a[left] == a[tleft]) then lcnt = lcnt + 1 else break end end for tright = right - 1, left + 1 do if(a[right] == a[tright]) then rcnt = rcnt + 1 else break end end cnt = cnt + lcnt * rcnt * 2 right = right - rcnt end else right = right - 1 end end end print(cnt)