結果
| 問題 | No.87 Advent Calendar Problem |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-09-18 02:58:27 |
| 言語 | C++11(廃止可能性あり) (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,018 bytes |
| 記録 | |
| コンパイル時間 | 395 ms |
| コンパイル使用メモリ | 59,832 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-19 06:54:41 |
| 合計ジャッジ時間 | 1,095 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
bool is_leap(long long 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;
}
*/
long long 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 (long long i = n_begin; i <= n; i++) {
// cout << i << endl;
days = (days + diff + is_leap(i)) % 7;
if (days == 0) {
ans++;
}
}
cout << ans << endl;
return 0;
}