結果

問題 No.87 Advent Calendar Problem
コンテスト
ユーザー trineutron
提出日時 2021-01-17 17:20:24
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 625 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,474 ms
コンパイル使用メモリ 210,884 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-17 03:41:19
合計ジャッジ時間 2,715 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

int main() {
    int64_t n;
    cin >> n;
    int64_t k = (n - 2014) / 400, r = (n - 2014) % 400;
    int64_t ans = 0;
    int d = 0;
    for (int i = 2015; i <= r + 2014; i++) {
        d++;
        if (i % 4 == 0) d++;
        if (i % 100 == 0) d--;
        if (i % 400 == 0) d++;
        d %= 7;
        if (d == 0) ans++;
    }
    int x = 0;
    for (int i = n + 1; i <= n + 400; i++) {
        d++;
        if (i % 4 == 0) d++;
        if (i % 100 == 0) d--;
        if (i % 400 == 0) d++;
        d %= 7;
        if (d == 0) x++;
    }
    cout << x * k + ans << endl;
}
0