結果
| 問題 |
No.87 Advent Calendar Problem
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2014-12-03 22:39:19 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,479 bytes |
| コンパイル時間 | 403 ms |
| コンパイル使用メモリ | 55,644 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-11 14:42:36 |
| 合計ジャッジ時間 | 1,171 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
#include <iostream>
#include <cstring>
using namespace std;
typedef long long ll;
/*
現実の 2015/07/23 は木曜日
日月火水木金土の順に0~6まで数字を振る
*/
bool is_leap(int y){
if(y % 400 == 0)return true;
if(y % 100 == 0)return false;
if(y % 4 == 0)return true;
return false;
}
int pr[400][7];
int store[3000];
ll solve(ll N){
memset(pr, -1, sizeof(pr));
int sz = 0;
int st = -1;
int w = 4;
for(int y=2015;y<=N;y++){
int m = y % 400;
if(pr[m][w] != -1){
st = pr[m][w];
break;
} else {
pr[m][w] = sz;
store[sz] = (w == 3);
++sz;
}
if(is_leap(y + 1)){
w = (w + 366) % 7;
} else {
w = (w + 365) % 7;
}
}
ll res = 0;
if(st == -1){
for(int i=0;i<sz;i++)res += store[i];
} else {
for(int i=0;i<st;i++)res += store[i];
ll acc = 0;
for(int i=st;i<sz;i++)acc += store[i];
N -= 2014;
N -= st;
ll loop_size = sz - st;
ll k = N / loop_size;
res += acc * k;
N -= k * loop_size;
for(int i=0;i<N;i++)res += store[i];
}
return res;
}
int main(){
ll N;
cin >> N;
cout << solve(N) << endl;
return 0;
}