結果

問題 No.1765 While Shining
ユーザー 👑 obakyanobakyan
提出日時 2022-01-02 20:50:56
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 604 bytes
コンパイル時間 376 ms
コンパイル使用メモリ 7,076 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-20 05:44:27
合計ジャッジ時間 2,293 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 32 ms
6,944 KB
testcase_10 AC 47 ms
6,944 KB
testcase_11 AC 39 ms
6,948 KB
testcase_12 AC 45 ms
6,940 KB
testcase_13 AC 41 ms
6,944 KB
testcase_14 AC 47 ms
6,940 KB
testcase_15 AC 50 ms
6,944 KB
testcase_16 AC 50 ms
6,944 KB
testcase_17 AC 50 ms
6,940 KB
testcase_18 AC 48 ms
6,940 KB
testcase_19 AC 48 ms
6,944 KB
testcase_20 AC 50 ms
6,944 KB
testcase_21 AC 50 ms
6,944 KB
testcase_22 AC 49 ms
6,940 KB
testcase_23 AC 50 ms
6,944 KB
testcase_24 AC 43 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local n = io.read("*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
  if i % 2 == 0 then a[i] = 1 - a[i] end
end
local right = {}
for i = 1, n do right[i] = n end
for i = n - 1, 1, -1 do
  if a[i] ~= a[i + 1] then
    right[i] = i
  else
    right[i] = right[i + 1]
  end
end
local ret = 0
for i = 1, n do
  if i % 2 == 1 then
    if a[i] == 1 then
      ret = ret + right[i] - i + 1
      if right[i] == n then ret = ret - 1 end
    end
  else
    if a[i] == 0 then
      ret = ret + right[i] - i + 1
      if right[i] == n then ret = ret - 1 end
    end
  end
  -- print(i, ret)
end
print(ret)
0