結果

問題 No.87 Advent Calendar Problem
ユーザー parukiparuki
提出日時 2018-01-12 18:54:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,014 bytes
コンパイル時間 1,607 ms
コンパイル使用メモリ 167,020 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-06 10:06:41
合計ジャッジ時間 5,677 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 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 AC 205 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
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;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

bool isLeap(ll year) {
    return year % 400 == 0 || (year % 100 && year % 4 == 0);
}

int week[102];
ll cnt[102];
const int R = 100000000;

int CNT[] = {
0,
14249713,
28499713,
42749713,
56999713,
71249713,
85499713,
99749713,
113999713,
128249713,
142499713,
156749713,
170999713,
185249713,
199499713,
213749713,
227999713,
242249713,
256499713,
270749713,
284999713,
299249713,
313499713,
327749713,
341999713,
356249713,
370499713,
384749713,
398999713,
413249713,
427499713,
441749713,
455999713,
470249713,
484499713,
498749713,
512999713,
527249713,
541499713,
555749713,
569999713,
584249713,
598499713,
612749713,
626999713,
641249713,
655499713,
669749713,
683999713,
698249713,
712499713,
726749713,
740999713,
755249713,
769499713,
783749713,
797999713,
812249713,
826499713,
840749713,
854999713,
869249713,
883499713,
897749713,
911999713,
926249713,
940499713,
954749713,
968999713,
983249713,
997499713,
1011749713,
1025999713,
1040249713,
1054499713,
1068749713,
1082999713,
1097249713,
1111499713,
1125749713,
1139999713,
1154249713,
1168499713,
1182749713,
1196999713,
1211249713,
1225499713,
1239749713,
1253999713,
1268249713,
1282499713,
1296749713,
1310999713,
1325249713,
1339499713,
1353749713,
1367999713,
1382249713,
1396499713,
1410749713,
1424999713,
};
int WEEK[] = {
0,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
};

ll f(ll l, ll r, int x) {
    ll res = 0;
    for (ll i = l; i < r; ++i) {
        if (i > l) {
            if (isLeap(i))x += 2;
            else x += 1;
            if (x >= 7)x -= 7;
        }
        if (!x)res++;
        if (i%R == 0) {
            week[i/R] = x;
            cnt[i/R] = res;
        }
    }
    return res;
}

void preCalc() {
    f(2014, 10000000001ll, 0);
    rep(i, 101) {
        cout << cnt[i] << "," << endl;
    }
    rep(i, 101) {
        cout << week[i] << "," << endl;
    }
}

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

    // preCalc();

    ll N;
    cin >> N;
    if (N<R) {
        cout << f(2014, N + 1, 0) - 1 << endl;
    } else {
        ll x = N / R*R;
        ll ans = cnt[x/R];
        ans += f(x, N + 1, week[x / R]);
        if (week[x / R] == 0)ans--;
        cout << ans << endl;
    }
}
0