結果

問題 No.87 Advent Calendar Problem
ユーザー hogeover30hogeover30
提出日時 2015-02-10 23:10:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 747 bytes
コンパイル時間 573 ms
コンパイル使用メモリ 59,720 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-05 23:03:44
合計ジャッジ時間 2,176 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,500 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;

int md[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
bool isLeap(int y) { return y%400==0?true:y%100==0?false:y%4==0; }
void next(int& y, int& m, int& d, int& w)
{
    if (++d>md[m]+(m==2&&isLeap(y))) { d=1; ++m; }
    if (m>12) { ++y; m=1; }
    if (++w==7) w=0;
}
int main()
{
    long long n;
    while (cin>>n) {
        int y=2014, m=7, d=23, w=0;
        int a[401]={};
        while (y<=min(2414LL, n)) {
            next(y, m, d, w);
            if (m==7 and d==23 and w==0) a[y-2014]=1;
        }
        for(int i=1;i<=400;++i) a[i]+=a[i-1];
        if (y>n) 
            cout<<a[n-2014]<<endl;
        else
            cout<<(n-2014)/400*a[400]+a[(n-2014)%400]<<endl;
    }
}
0