結果
問題 | No.87 Advent Calendar Problem |
ユーザー |
![]() |
提出日時 | 2014-12-07 00:30:09 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 938 bytes |
コンパイル時間 | 654 ms |
コンパイル使用メモリ | 61,212 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-11 15:56:04 |
合計ジャッジ時間 | 1,465 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#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;}