Last active
November 10, 2015 04:07
-
-
Save whatalnk/c91631a820997fb1ed85 to your computer and use it in GitHub Desktop.
Codeforces #330 Div2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# [Problem - A - Codeforces](http://codeforces.com/contest/595/problem/A) | |
n, m = gets.chomp.split(" ").map(&:to_i) | |
ans = 0 | |
n.times do |i| | |
rooms = gets.chomp.split(" ").map(&:to_i) | |
rooms.each_slice(2) do |a, b| | |
if (a == 1) or (b == 1) then | |
ans += 1 | |
end | |
end | |
end | |
puts ans |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# [Problem - B - Codeforces](http://codeforces.com/contest/595/problem/B) | |
n, k = gets.chomp.split(" ").map(&:to_i) | |
aa = gets.chomp.split(" ").map(&:to_i) | |
bb = gets.chomp.split(" ").map(&:to_i) | |
if k == 1 then | |
i = [aa, bb].transpose.map{|a, b| b % a == 0 ? 9 / a : 9 / a + 1} | |
puts i.inject(:*).modulo(10**9 + 7) | |
else | |
phone_parts = [] | |
aa.zip(bb).each do |a, b| | |
phone_part = 1 | |
num_all = (10**k - 1) / a | |
upper = (((b + 1) * 10**(k-1))) | |
lower = ((b * 10**(k-1)) - 1) | |
num_exclude = upper / a - lower / a | |
phone_part += (num_all - num_exclude) | |
if ((b + 1) * 10**(k - 1)) % a == 0 then | |
phone_part += 1 | |
end | |
phone_parts << phone_part | |
end | |
puts phone_parts.inject(:*).modulo(10**9 + 7) | |
end |
Author
whatalnk
commented
Nov 9, 2015
- A
- B
- C
- D
- E
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment