結果
| 問題 |
No.87 Advent Calendar Problem
|
| コンテスト | |
| ユーザー |
not_522
|
| 提出日時 | 2015-07-22 02:28:55 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,697 bytes |
| コンパイル時間 | 1,174 ms |
| コンパイル使用メモリ | 157,988 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-08 11:45:13 |
| 合計ジャッジ時間 | 2,085 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
inline bool isLeapYear(int year) {
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}
inline int countLeapYear(int year) {
return year / 4 - year / 100 + year / 400;
}
inline int getMaxDay(int year, int month) {
const int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (month == 2) return isLeapYear(year) ? 29 : 28;
return days[month];
}
struct Day {
int year, month, day;
enum {SUN, MON, TUE, WED, THU, FRI, SAT};
Day() : year(0), month(0), day(0) {}
Day(int year, int month, int day) : year(year), month(month), day(day) {}
int fairfield() const {
int y = year, m = month;
if (m <= 2) --y, m += 12;
return 365 * y + countLeapYear(y) + (153 * (m + 1) / 5) + day - 428;
}
int operator-(const Day& day) const {
return fairfield() - day.fairfield();
}
bool operator<(const Day& day) const {
if (year != day.year) return year < day.year;
if (month != day.month) return month < day.month;
return this->day < day.day;
}
Day operator++() {
++day;
if (getMaxDay(year, month) < day) {
++month;
day = 1;
if (month == 13) {
++year;
month = 1;
}
}
return *this;
}
int weekday() {
return fairfield() % 7;
}
};
int solve(long long n) {
Day day(0, 7, 23);
int res = 0;
for (int i = 0; i < 400; ++i) {
day.year = i;
if (day.weekday() == Day::WED) ++res;
}
res *= n / 400;
for (int i = 0; i <= n % 400; ++i) {
day.year = i;
if (day.weekday() == Day::WED) ++res;
}
return res;
}
int main() {
long long n;
cin >> n;
cout << solve(n) - solve(2014) << endl;
}
not_522