結果

問題 No.87 Advent Calendar Problem
ユーザー rpy3cpp
提出日時 2015-08-08 19:30:13
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 890 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-07-18 05:59:47
合計ジャッジ時間 1,897 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(year):
    q, r = divmod(year-2000, 400)
    return q * count400(399) + count400(r) - 3

def count400(year):
    '''
    水曜日を0
    木曜日を1
    金曜日を2
    ...
    火曜日を6
    であらわすとする。
    400年単位で切りが良いので、2000年から数え始めることにする。
    2014 0
    2013 6
    2012 5
    2011 3
    2010 2
    2009 1
    2008 0
    2007 5
    2006 4
    2005 3
    2004 2
    2003 0
    2002 6
    2001 5
    2000 4
    '''
    weekday = 4
    count = 0
    for n in range(1, year + 1):
        weekday += 1 + is_leap_year(n)
        weekday %= 7
        if weekday == 0:
            count += 1
    return count

def is_leap_year(n):
    if n % 400 == 0:
        return True
    if n % 100 == 0:
        return False
    if n % 4 == 0:
        return True
    return False

year = int(input())
print(solve(year))
0