結果

問題 No.87 Advent Calendar Problem
ユーザー hotpepsihotpepsi
提出日時 2014-12-07 00:30:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 938 bytes
コンパイル時間 509 ms
コンパイル使用メモリ 60,396 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-02 09:06:16
合計ジャッジ時間 1,659 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <sstream>

using namespace std;

typedef long long LL;

bool is_uruu(LL year) {
	return (year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0);
}

LL solve(LL N)
{
	LL ans = 0;
	LL year;
	int w = 0;
	for (year = 2015; year <= N && year < 400 * 7; ++year) {
		int days = 365 + is_uruu(year);
		w = (w + days) % 7;
		ans += w == 0;
	}
	if (N > 400 * 7 * 2) {
		LL t = 0;
		for (; year < 400 * 7 * 2; ++year) {
			int days = 365 + is_uruu(year);
			w = (w + days) % 7;
			t += w == 0;
		}
		LL a = ((N - year) / (400 * 7));
		ans += (a + 1) * t;
		year += a * 400 * 7;
	}
	for (; year <= N; ++year) {
		int days = 365 + is_uruu(year);
		w = (w + days) % 7;
		ans += w == 0;
	}
	return ans;
}

int main(int argc, char *argv[])
{
	string s;
	getline(cin, s);
	LL N;
	sscanf(s.c_str(), "%lld", &N);
	cout << solve(N) << endl;
	return 0;
}
0