結果

問題 No.87 Advent Calendar Problem
ユーザー masamasa
提出日時 2015-05-11 21:03:41
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 978 bytes
コンパイル時間 451 ms
コンパイル使用メモリ 61,292 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 02:44:17
合計ジャッジ時間 3,321 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 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 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;
bool is_leap(int y) {
	return  y % 4 == 0 && (y % 100 > 0 || y % 400 == 0);
}

int main() {
	//2015≤N≤10000000000=10^10
	long long n;
	cin >> n;

	int diff = 365 % 7;
	long long ans = 0;
	int days = 0; //曜日


/*
	for (int i = 0; i < 400; i++) {
		if (i % 400 == 0) {
			printf("%5d, %d\n", i, days);
		}
		days = (days + diff + is_leap(i)) % 7;
	}
*/
	int sameInLoop = 0;
	for (int i = 2015; i < 2415; i++) {
		days = (days + diff + is_leap(i)) % 7;
		if (days == 0) {
			sameInLoop++;
		}
	}

	long long n_loop = (n - 2015) / 400;
	ans = n_loop * sameInLoop;
	long long n_begin = 2015 + n_loop * 400;
	//2014年7月23日(水)に初めてのyukicoder no.1 として
	//2014/7/23を days = 0 として
	for (int i = n_begin; i <= n; i++) {
		days = (days + diff + is_leap(i)) % 7;
		if (days == 0) {
			ans++;
		}
	}

	cout << ans << endl;
	return 0;
}
0