結果
問題 | No.87 Advent Calendar Problem |
ユーザー |
![]() |
提出日時 | 2015-02-10 23:10:02 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 747 bytes |
コンパイル時間 | 427 ms |
コンパイル使用メモリ | 57,556 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-23 18:23:52 |
合計ジャッジ時間 | 1,458 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#include <iostream>#include <algorithm>using namespace std;int md[]={0,31,28,31,30,31,30,31,31,30,31,30,31};bool isLeap(int y) { return y%400==0?true:y%100==0?false:y%4==0; }void next(int& y, int& m, int& d, int& w){if (++d>md[m]+(m==2&&isLeap(y))) { d=1; ++m; }if (m>12) { ++y; m=1; }if (++w==7) w=0;}int main(){long long n;while (cin>>n) {int y=2014, m=7, d=23, w=0;int a[401]={};while (y<=min(2414LL, n)) {next(y, m, d, w);if (m==7 and d==23 and w==0) a[y-2014]=1;}for(int i=1;i<=400;++i) a[i]+=a[i-1];if (y>n)cout<<a[n-2014]<<endl;elsecout<<(n-2014)/400*a[400]+a[(n-2014)%400]<<endl;}}