結果
問題 | No.87 Advent Calendar Problem |
ユーザー |
![]() |
提出日時 | 2015-06-03 00:35:19 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 981 bytes |
コンパイル時間 | 541 ms |
コンパイル使用メモリ | 61,484 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-06 13:50:25 |
合計ジャッジ時間 | 1,529 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#include <iostream> #include <vector> using namespace std; bool isLeap(long long year) { if (year % 400 == 0) { return true; } else if (year % 100 == 0) { return false; } else if (year % 4 == 0) { return true; } return false; } int main() { long long n; cin >> n; vector<int> days; int sameDayCount = 0; int day = isLeap(2015) ? 2 : 1; days.push_back(day); for (int i = 1; ; ++i) { day = (day + (isLeap(2015 + i) ? 2 : 1)) % 7; if (i >= 400 && days[i - 400] == day) { break; } if (day == 0) { ++sameDayCount; } days.push_back(day); } long long remaining = n - 2015; long long repeatTimes = remaining / days.size(); long long result = repeatTimes * sameDayCount; remaining %= days.size(); day = (isLeap(2015 + days.size() * repeatTimes) ? 2 : 1); for (long long i = 2015 + days.size() * repeatTimes + 1; i <= n; ++i) { day = (day + (isLeap(i) ? 2 : 1)) % 7; if (day == 0) { ++result; } } cout << result << endl; return 0; }