結果
問題 | No.1092 modular arithmetic |
ユーザー | 👑 obakyan |
提出日時 | 2020-06-24 12:46:36 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
AC
|
実行時間 | 1,862 ms / 2,000 ms |
コード長 | 1,092 bytes |
コンパイル時間 | 112 ms |
コンパイル使用メモリ | 5,328 KB |
実行使用メモリ | 4,380 KB |
最終ジャッジ日時 | 2023-09-16 21:03:55 |
合計ジャッジ時間 | 20,376 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 48 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 521 ms
4,376 KB |
testcase_04 | AC | 501 ms
4,376 KB |
testcase_05 | AC | 549 ms
4,376 KB |
testcase_06 | AC | 377 ms
4,380 KB |
testcase_07 | AC | 407 ms
4,380 KB |
testcase_08 | AC | 465 ms
4,380 KB |
testcase_09 | AC | 434 ms
4,380 KB |
testcase_10 | AC | 384 ms
4,376 KB |
testcase_11 | AC | 426 ms
4,376 KB |
testcase_12 | AC | 429 ms
4,380 KB |
testcase_13 | AC | 17 ms
4,376 KB |
testcase_14 | AC | 20 ms
4,376 KB |
testcase_15 | AC | 5 ms
4,380 KB |
testcase_16 | AC | 15 ms
4,380 KB |
testcase_17 | AC | 20 ms
4,380 KB |
testcase_18 | AC | 614 ms
4,376 KB |
testcase_19 | AC | 365 ms
4,380 KB |
testcase_20 | AC | 714 ms
4,380 KB |
testcase_21 | AC | 484 ms
4,380 KB |
testcase_22 | AC | 669 ms
4,380 KB |
testcase_23 | AC | 1,860 ms
4,376 KB |
testcase_24 | AC | 468 ms
4,380 KB |
testcase_25 | AC | 1,448 ms
4,380 KB |
testcase_26 | AC | 1,400 ms
4,376 KB |
testcase_27 | AC | 267 ms
4,376 KB |
testcase_28 | AC | 1,245 ms
4,380 KB |
testcase_29 | AC | 1,862 ms
4,380 KB |
testcase_30 | AC | 1,372 ms
4,380 KB |
testcase_31 | AC | 184 ms
4,380 KB |
testcase_32 | AC | 1,213 ms
4,376 KB |
ソースコード
local mod = false local mfl = math.floor local function bmul(x, y) if x < y then x, y = y, x end local res = 0 while 0 < y do if y % 2 == 1 then res = (res + x) % mod y = y - 1 end x = (x + x) % mod y = mfl(y / 2) end return res end local function badd(x, y) return (x + y) % mod end local function bsub(x, y) return x < y and x - y + mod or x - y end local function modpow(src, pow) local res = 1 while 0 < pow do if pow % 2 == 1 then res = bmul(res, src) pow = pow - 1 end src = bmul(src, src) pow = mfl(pow / 2) end return res end local function modinv(src) return modpow(src, mod - 2) end local p, n = io.read("*n", "*n") mod = p local a = {} for i = 1, n do a[i] = io.read("*n") end io.read() local s = io.read() local ans = a[1] for i = 1, n - 1 do local ss = s:sub(i, i) if ss == "+" then ans = badd(ans, a[i + 1]) elseif ss == "-" then ans = bsub(ans, a[i + 1]) elseif ss == "*" then ans = bmul(ans, a[i + 1]) else ans = bmul(ans, modinv(a[i + 1])) end end print(ans)