結果

問題 No.1331 Moving Penguin
ユーザー yuruhiyayuruhiya
提出日時 2021-01-09 16:16:20
言語 Crystal
(1.11.2)
結果
AC  
実行時間 332 ms / 1,500 ms
コード長 1,795 bytes
コンパイル時間 14,341 ms
コンパイル使用メモリ 293,420 KB
実行使用メモリ 10,240 KB
最終ジャッジ日時 2024-04-25 05:04:27
合計ジャッジ時間 21,924 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 245 ms
10,112 KB
testcase_05 AC 246 ms
8,448 KB
testcase_06 AC 246 ms
8,448 KB
testcase_07 AC 245 ms
8,448 KB
testcase_08 AC 241 ms
8,704 KB
testcase_09 AC 245 ms
7,936 KB
testcase_10 AC 260 ms
8,704 KB
testcase_11 AC 248 ms
8,704 KB
testcase_12 AC 252 ms
8,064 KB
testcase_13 AC 250 ms
8,704 KB
testcase_14 AC 252 ms
8,704 KB
testcase_15 AC 249 ms
8,704 KB
testcase_16 AC 244 ms
8,704 KB
testcase_17 AC 249 ms
8,704 KB
testcase_18 AC 248 ms
8,832 KB
testcase_19 AC 247 ms
8,704 KB
testcase_20 AC 245 ms
8,704 KB
testcase_21 AC 245 ms
8,704 KB
testcase_22 AC 254 ms
8,704 KB
testcase_23 AC 246 ms
8,704 KB
testcase_24 AC 249 ms
8,064 KB
testcase_25 AC 241 ms
8,704 KB
testcase_26 AC 245 ms
10,112 KB
testcase_27 AC 249 ms
10,112 KB
testcase_28 AC 255 ms
10,112 KB
testcase_29 AC 248 ms
10,112 KB
testcase_30 AC 48 ms
5,376 KB
testcase_31 AC 104 ms
6,400 KB
testcase_32 AC 40 ms
5,376 KB
testcase_33 AC 74 ms
6,016 KB
testcase_34 AC 137 ms
7,552 KB
testcase_35 AC 306 ms
10,240 KB
testcase_36 AC 295 ms
10,240 KB
testcase_37 AC 289 ms
10,112 KB
testcase_38 AC 53 ms
5,376 KB
testcase_39 AC 235 ms
9,728 KB
testcase_40 AC 87 ms
6,400 KB
testcase_41 AC 248 ms
10,240 KB
testcase_42 AC 293 ms
10,112 KB
testcase_43 AC 298 ms
10,112 KB
testcase_44 AC 300 ms
10,112 KB
testcase_45 AC 331 ms
10,112 KB
testcase_46 AC 332 ms
10,240 KB
testcase_47 AC 332 ms
10,112 KB
testcase_48 AC 244 ms
8,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

lib C
  fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64
end

class String
  def to_i64
    C.strtoll(self, nil, 10)
  end
end

struct Mint
  @@MOD = 1_000_000_007i64

  def self.mod
    @@MOD
  end

  def self.zero
    Mint.new(0)
  end

  def initialize(n)
    @n = n.to_i64 % @@MOD
  end

  getter n : Int64

  def + : self
    self
  end

  def - : self
    Mint.new(n != 0 ? @@MOD - @n : 0)
  end

  def +(m)
    Mint.new(@n + m.to_i64 % @@MOD)
  end

  def -(m)
    Mint.new(@n - m.to_i64 % @@MOD)
  end

  def *(m)
    Mint.new(@n * m.to_i64 % @@MOD)
  end

  def /(m)
    raise DivisionByZeroError.new if m == 0
    a, b, u, v = m.to_i64, @@MOD, 1i64, 0i64
    while b != 0
      t = a // b
      a -= t * b
      a, b = b, a
      u -= t * v
      u, v = v, u
    end
    Mint.new(@n * u)
  end

  def //(m)
    self / m
  end

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

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

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

  def succ
    self + 1
  end

  def pred
    self - 1
  end

  def to_i64 : Int64
    @n
  end

  delegate to_s, to: @n
  delegate inspect, to: @n
end

struct Int
  def to_mint : Mint
    Mint.new(self)
  end
end

class String
  def to_mint : Mint
    Mint.new(self)
  end
end

n = read_line.to_i
a = read_line.split.map(&.to_i)

sqrt_n = Math.sqrt(n).to_i
plus = Array.new(sqrt_n) { |i| [Mint.zero] * i }

dp = [Mint.zero] * n
dp[0] = Mint.new(1)
(0...n).each do |i|
  (1...sqrt_n).each do |x|
    dp[i] += plus[x][i % x]
  end

  if a[i] < sqrt_n
    plus[a[i]][i % a[i]] += dp[i]
  else
    (i + a[i]...n).step(a[i]) { |j|
      dp[j] += dp[i]
    }
  end
  if i + 1 < n && a[i] > 1
    dp[i + 1] += dp[i]
  end
end
puts dp[n - 1]
0