結果

問題 No.87 Advent Calendar Problem
ユーザー RCCWRCCW
提出日時 2017-02-26 10:35:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,515 bytes
コンパイル時間 1,628 ms
コンパイル使用メモリ 144,192 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-02 09:48:46
合計ジャッジ時間 2,955 ms
ジャッジサーバーID
(参考情報)
judge11 / judge16
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 2 ms
4,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
//2015 年から N 年まで(両端を含む)のうちで,
//7 月 23 日の曜日が 2014 年と一致するのは何年あるかを求める問題.
//カレンダーはずっとグレゴリオ暦を用いる.
//2015≤N≤10000000000 (1010)
int main(){
	long n;
	int a[400],b,i,t;
	//tは曜日,iは年,aは曜日一致カウンター。もしa[X]=0なら(X)には年が入る。それは、曜日一致したとしてt増やす
	t=0;b=1;

	//2014年の曜日を0としておく
	//a[i]にi年後の曜日を、bに400年の内2014年と同じ曜日だった年の数を保存
	//400までカウントするのは、400周期でタイミングが一致するから
	for(i=2015;i<2014+400;i++){
	//最初の400年間の曜日を調べる
			//3項演算子で0or not0で計算する
		//うるう年だったら1追加し、そうでないと2追加する
		t=(t+(i%4?1:i%100?2:i%400?1:2))%7;
		//365日は52週+1日なので、ある年の7月の曜日は、
		//その年がうるう年でなければ前の年+1、
		//うるう年なら前の年+2となる
		a[i-2014]=t;
		//2414までに一つbプラスが入った。
		if(t==0)b++;
	}
	scanf("%ld",&n);
	//bは上の計算結果から57とわかっている。
	//2014+400年周期で57をかけてやる。
	t=(n-2014)/400*b;
	//未来側から400年ずつまとめて処理
	for(n=(n-2014)%400;n;n--)if(a[n]==0)t++;
	//余ったところを1年ずつ調べる
	printf("%d",t);
	return 0;
}
0