結果

問題 No.87 Advent Calendar Problem
ユーザー peroonperoon
提出日時 2019-04-24 14:20:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,511 bytes
コンパイル時間 1,466 ms
コンパイル使用メモリ 163,208 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 10:45:11
合計ジャッジ時間 2,413 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

bool is_ururu(ll y){
    if(y%400==0) return true;
    if(y%100==0) return false;
    if(y%4==0) return true;
    return false;
}

// start〜end年まで愚直に数えたときの重なりの数
ll calc_count(ll start, ll end){
    ll zure = 0;
    ll count = 0;
    FOR(y, start, end+1){
        if(is_ururu(y)){
            zure+=2;
        }else{
            zure+=1;
        }
        zure %= 7;
        if(zure==0){
            count++;
        }
    }
    return count;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    ll N;
    cin >> N;

    // 普通にやる
    if(N<5000){
        ll ans = calc_count(2015, N);
        p(ans);
        return 0;
    }

    ll num_per_400_years = 0;
    ll zure = 0;
    FOR(i, 0, 400){
        if(is_ururu(i)){
            zure += 2;
        }else{
            zure += 1;
        }
        zure %= 7;
        if(zure==0){
            num_per_400_years++;
        }
    }
    
    // 2400年まで
    ll count = calc_count(2015, 2399);
    ll diff = N - 2399;
    ll loop = diff / 400;
    ll rest = diff % 400;
    
    count += loop * num_per_400_years;

    count += calc_count(2400, 2400+rest);
    p(count);
    
    return 0;
}
0