結果

問題 No.1258 コインゲーム
ユーザー semisagisemisagi
提出日時 2020-10-16 21:46:20
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,622 ms / 2,000 ms
コード長 524 bytes
コンパイル時間 391 ms
コンパイル使用メモリ 11,356 KB
実行使用メモリ 15,476 KB
最終ジャッジ日時 2023-09-28 02:41:22
合計ジャッジ時間 51,508 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 361 ms
15,396 KB
testcase_01 AC 436 ms
15,364 KB
testcase_02 AC 199 ms
15,152 KB
testcase_03 AC 1,269 ms
15,476 KB
testcase_04 AC 1,434 ms
15,156 KB
testcase_05 AC 303 ms
15,232 KB
testcase_06 AC 1,122 ms
15,280 KB
testcase_07 AC 168 ms
15,156 KB
testcase_08 AC 154 ms
15,252 KB
testcase_09 AC 553 ms
15,384 KB
testcase_10 AC 1,268 ms
15,152 KB
testcase_11 AC 1,400 ms
15,388 KB
testcase_12 AC 1,047 ms
15,208 KB
testcase_13 AC 356 ms
15,236 KB
testcase_14 AC 165 ms
15,272 KB
testcase_15 AC 1,240 ms
15,272 KB
testcase_16 AC 302 ms
15,432 KB
testcase_17 AC 1,410 ms
15,348 KB
testcase_18 AC 556 ms
15,272 KB
testcase_19 AC 526 ms
15,372 KB
testcase_20 AC 1,067 ms
15,392 KB
testcase_21 AC 1,342 ms
15,404 KB
testcase_22 AC 946 ms
15,220 KB
testcase_23 AC 707 ms
15,272 KB
testcase_24 AC 307 ms
15,416 KB
testcase_25 AC 699 ms
15,268 KB
testcase_26 AC 585 ms
15,264 KB
testcase_27 AC 1,291 ms
15,144 KB
testcase_28 AC 381 ms
15,144 KB
testcase_29 AC 410 ms
15,216 KB
testcase_30 AC 1,582 ms
15,160 KB
testcase_31 AC 442 ms
15,268 KB
testcase_32 AC 232 ms
15,396 KB
testcase_33 AC 1,095 ms
15,140 KB
testcase_34 AC 1,310 ms
15,148 KB
testcase_35 AC 508 ms
15,456 KB
testcase_36 AC 1,323 ms
15,208 KB
testcase_37 AC 557 ms
15,228 KB
testcase_38 AC 1,296 ms
15,268 KB
testcase_39 AC 391 ms
15,388 KB
testcase_40 AC 1,612 ms
15,352 KB
testcase_41 AC 1,622 ms
15,224 KB
testcase_42 AC 1,610 ms
15,272 KB
testcase_43 AC 1,616 ms
15,272 KB
testcase_44 AC 1,602 ms
15,400 KB
testcase_45 AC 1,594 ms
15,232 KB
testcase_46 AC 1,615 ms
15,352 KB
testcase_47 AC 1,591 ms
15,396 KB
testcase_48 AC 1,601 ms
15,360 KB
testcase_49 AC 1,616 ms
15,360 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

s = gets.to_i

MOD = 10**9 + 7

class Integer
    def modpow(n)
        if n.zero?
            1
        elsif n.odd?
            self * self.modpow(n - 1) % MOD
        else
            (self * self % MOD).modpow(n / 2)
        end
    end

    def inverse
        self.modpow(MOD - 2)
    end
end

s.times do
    n, m, x = gets.split.map(&:to_i)
    if x == 0
        puts ((1 + m).modpow(n) + (1 - m).modpow(n)) * 2.inverse % MOD
    else
        puts ((1 + m).modpow(n) - (1 - m).modpow(n)) * 2.inverse % MOD
    end
end
0