結果

問題 No.87 Advent Calendar Problem
ユーザー DialBirdDialBird
提出日時 2017-02-26 10:37:11
言語 Ruby
(3.3.0)
結果
AC  
実行時間 86 ms / 5,000 ms
コード長 947 bytes
コンパイル時間 316 ms
コンパイル使用メモリ 11,304 KB
実行使用メモリ 15,464 KB
最終ジャッジ日時 2023-09-02 09:48:52
合計ジャッジ時間 5,474 ms
ジャッジサーバーID
(参考情報)
judge16 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,376 KB
testcase_01 AC 84 ms
15,172 KB
testcase_02 AC 84 ms
15,464 KB
testcase_03 AC 84 ms
15,240 KB
testcase_04 AC 84 ms
15,172 KB
testcase_05 AC 82 ms
15,372 KB
testcase_06 AC 82 ms
15,456 KB
testcase_07 AC 83 ms
15,108 KB
testcase_08 AC 82 ms
15,100 KB
testcase_09 AC 84 ms
15,368 KB
testcase_10 AC 82 ms
15,312 KB
testcase_11 AC 83 ms
15,364 KB
testcase_12 AC 83 ms
15,376 KB
testcase_13 AC 84 ms
15,300 KB
testcase_14 AC 82 ms
15,212 KB
testcase_15 AC 82 ms
15,368 KB
testcase_16 AC 82 ms
15,172 KB
testcase_17 AC 82 ms
15,344 KB
testcase_18 AC 85 ms
15,072 KB
testcase_19 AC 86 ms
15,456 KB
testcase_20 AC 86 ms
15,312 KB
testcase_21 AC 85 ms
15,328 KB
testcase_22 AC 82 ms
15,200 KB
testcase_23 AC 83 ms
15,212 KB
testcase_24 AC 82 ms
15,180 KB
testcase_25 AC 83 ms
15,280 KB
testcase_26 AC 84 ms
15,192 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'date'

class Yukicoder
  def initialize
    @n = gets.to_i
  end

  def run
    # nが2400以下の時端数の計算
    first_span = Array.new((2400 - 2014) + 1, 0)

    first_cnt = 0
    wday = 0
    2015.upto(2400) do |i|
      if i % 400 == 0 || i % 4 == 0 && i % 100 != 0
        wday += 2
      else
        wday += 1
      end
      wday %= 7
      first_cnt += 1  if wday == 0
      first_span[i-2014] = first_cnt
    end

    # 400 * 7(足され方が一周するように一週間の日数をかける)
    span_2800 = Array.new(2800, 0)
    cnt = 0
    1.upto(2799) do |i|
      if i % 400 == 0 || i % 4 == 0 && i % 100 != 0
        wday += 2
      else
        wday += 1
      end
      wday %= 7
      cnt += 1  if wday == 0
      span_2800[i] = cnt
    end

    if @n <= 2400
      return first_span[@n-2014]
    end
    first_cnt + (@n - 2400) / 2800 * cnt + span_2800[(@n - 2400) % 2800]
  end
end

puts Yukicoder.new.run
0