結果

問題 No.1092 modular arithmetic
ユーザー yuruhiyayuruhiya
提出日時 2020-08-01 17:06:31
言語 Ruby
(3.3.0)
結果
AC  
実行時間 335 ms / 2,000 ms
コード長 1,143 bytes
コンパイル時間 597 ms
コンパイル使用メモリ 11,208 KB
実行使用メモリ 29,128 KB
最終ジャッジ日時 2023-09-22 11:01:36
合計ジャッジ時間 9,093 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,044 KB
testcase_01 AC 230 ms
29,128 KB
testcase_02 AC 76 ms
15,140 KB
testcase_03 AC 259 ms
28,816 KB
testcase_04 AC 223 ms
27,600 KB
testcase_05 AC 225 ms
28,008 KB
testcase_06 AC 185 ms
22,892 KB
testcase_07 AC 223 ms
27,608 KB
testcase_08 AC 239 ms
28,672 KB
testcase_09 AC 217 ms
27,124 KB
testcase_10 AC 201 ms
23,096 KB
testcase_11 AC 213 ms
26,512 KB
testcase_12 AC 185 ms
22,620 KB
testcase_13 AC 189 ms
26,520 KB
testcase_14 AC 204 ms
27,948 KB
testcase_15 AC 105 ms
17,336 KB
testcase_16 AC 172 ms
22,380 KB
testcase_17 AC 205 ms
27,864 KB
testcase_18 AC 248 ms
28,760 KB
testcase_19 AC 186 ms
22,880 KB
testcase_20 AC 256 ms
28,988 KB
testcase_21 AC 214 ms
26,864 KB
testcase_22 AC 243 ms
28,784 KB
testcase_23 AC 297 ms
26,736 KB
testcase_24 AC 146 ms
18,812 KB
testcase_25 AC 245 ms
22,940 KB
testcase_26 AC 288 ms
26,812 KB
testcase_27 AC 112 ms
16,052 KB
testcase_28 AC 249 ms
22,868 KB
testcase_29 AC 335 ms
28,588 KB
testcase_30 AC 248 ms
22,744 KB
testcase_31 AC 98 ms
15,840 KB
testcase_32 AC 222 ms
22,736 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:84: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

class ModInt
	@@mod = 1_000_000_007

	def initialize(n)
		@n = n.to_i % @@mod
	end

	def self.zero
		ModInt.new(0)
	end

	def self.mod=(m)
		@@mod = m.to_i
	end

	def +@
		self
	end

	def -@
		ModInt.new(n != 0 ? @@mod - @n : 0)
	end

	def +(m)
		ModInt.new(@n + m.to_i % @@mod)
	end

	def -(m)
		ModInt.new(@n - m.to_i % @@mod)
	end

	def *(m)
		ModInt.new(@n * m.to_i % @@mod)
	end

	def /(m)
		raise DivisionByZeroError.new if m == 0
		a, b, u, v = m.to_i, @@mod, 1, 0
		while b != 0
			t = a / b
			a -= t * b
			a, b = b, a
			u -= t * v
			u, v = v, u
		end
		ModInt.new(@n * u)
	end

	def **(m)
		t, res = self, ModInt.new(1)
		while m > 0
			res *= t if m.odd?
			t *= t
			m >>= 1
		end
		res
	end

	def ==(m)
		@n == m.to_i
	end

	def !=(m)
		@n != m.to_i
	end

	def succ
		self + 1
	end

	def pred
		self - 1
	end

	def to_i
		@n
	end

	def to_s
		@n.to_s
	end
end

ModInt.mod, n = gets.split.map &:to_i
a = gets.split.map { |i| ModInt.new(i) }
s = gets.chomp
puts s.size.times.reduce(a.first) { |x, i|
		case s[i]
		when '+'
			x + a[i + 1]
		when '-'
			x - a[i + 1]
		when '*'
			x * a[i + 1]
		else
			x / a[i + 1]
		end
     }
0