結果

問題 No.1092 modular arithmetic
ユーザー laneguelanegue
提出日時 2020-09-07 23:14:28
言語 Crystal
(1.11.2)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 520 bytes
コンパイル時間 15,846 ms
コンパイル使用メモリ 254,080 KB
実行使用メモリ 11,496 KB
最終ジャッジ日時 2023-09-13 12:04:59
合計ジャッジ時間 18,853 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 18 ms
11,496 KB
testcase_02 AC 3 ms
4,384 KB
testcase_03 AC 31 ms
9,948 KB
testcase_04 AC 24 ms
9,132 KB
testcase_05 AC 26 ms
9,080 KB
testcase_06 AC 20 ms
8,296 KB
testcase_07 AC 24 ms
9,028 KB
testcase_08 AC 28 ms
9,796 KB
testcase_09 AC 24 ms
9,068 KB
testcase_10 AC 21 ms
8,288 KB
testcase_11 AC 23 ms
8,980 KB
testcase_12 AC 20 ms
8,260 KB
testcase_13 AC 10 ms
7,908 KB
testcase_14 AC 12 ms
7,928 KB
testcase_15 AC 4 ms
5,144 KB
testcase_16 AC 9 ms
6,760 KB
testcase_17 AC 12 ms
7,832 KB
testcase_18 AC 31 ms
9,772 KB
testcase_19 AC 20 ms
8,276 KB
testcase_20 AC 32 ms
9,952 KB
testcase_21 AC 24 ms
9,000 KB
testcase_22 AC 30 ms
9,744 KB
testcase_23 AC 55 ms
8,876 KB
testcase_24 AC 19 ms
5,676 KB
testcase_25 AC 42 ms
8,032 KB
testcase_26 AC 52 ms
8,920 KB
testcase_27 AC 10 ms
5,020 KB
testcase_28 AC 42 ms
8,268 KB
testcase_29 AC 65 ms
9,756 KB
testcase_30 AC 43 ms
8,276 KB
testcase_31 AC 7 ms
4,784 KB
testcase_32 AC 39 ms
7,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

pr, n = read_line.split.map{|i|i.to_i}
A = read_line.split.map{|i|i.to_i}
S = read_line
r = A[0].to_i64
def pow_mod(a, n, m)
    r = 1_i64
    while n > 0
        if n % 2 == 1
            r *= a
            r %= m
        end
        a **= 2
        a %= m
        n >>= 1
    end
    r
end
(n - 1).times{|i|
    case S[i]
    when '+'
        r += A[i + 1]
    when '-'
        r -= A[i + 1]
    when '*'
        r *= A[i + 1]
    when '/'
        r *= pow_mod(A[i + 1].to_i64, pr - 2, pr)
    end
    r %= pr
}
puts r
0