結果

問題 No.87 Advent Calendar Problem
ユーザー YamaKasaYamaKasa
提出日時 2018-10-17 03:51:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 124 ms / 5,000 ms
コード長 731 bytes
コンパイル時間 2,051 ms
コンパイル使用メモリ 77,028 KB
実行使用メモリ 41,608 KB
最終ジャッジ日時 2024-04-20 20:43:11
合計ジャッジ時間 6,304 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
40,124 KB
testcase_01 AC 117 ms
41,052 KB
testcase_02 AC 108 ms
40,208 KB
testcase_03 AC 110 ms
41,184 KB
testcase_04 AC 102 ms
39,928 KB
testcase_05 AC 116 ms
41,156 KB
testcase_06 AC 124 ms
41,512 KB
testcase_07 AC 109 ms
40,328 KB
testcase_08 AC 116 ms
41,124 KB
testcase_09 AC 123 ms
41,376 KB
testcase_10 AC 118 ms
41,176 KB
testcase_11 AC 116 ms
41,208 KB
testcase_12 AC 103 ms
40,072 KB
testcase_13 AC 120 ms
41,300 KB
testcase_14 AC 111 ms
41,064 KB
testcase_15 AC 114 ms
41,440 KB
testcase_16 AC 115 ms
40,968 KB
testcase_17 AC 116 ms
41,096 KB
testcase_18 AC 114 ms
41,180 KB
testcase_19 AC 113 ms
41,164 KB
testcase_20 AC 113 ms
41,356 KB
testcase_21 AC 119 ms
41,300 KB
testcase_22 AC 116 ms
41,212 KB
testcase_23 AC 115 ms
41,608 KB
testcase_24 AC 104 ms
39,944 KB
testcase_25 AC 115 ms
41,000 KB
testcase_26 AC 116 ms
41,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long N = scan.nextLong();
		scan.close();
		long t = N - 2014;
		long h = zeller(2014, 7, 23);
		int cnt = 0;
		for(int i = 0; i < 400; i++) {
			if(h == zeller(2015 + i, 7, 23)) {
				cnt ++;
			}
		}
		long k = t / 400;
		long ans = k * cnt;
		long s = 2015 + k *  400;

		for(long i = s; i <= N; i++) {
			if(h == zeller(i, 7, 23)) {
				ans++;
			}
		}
		System.out.println(ans);

	}
	static long zeller(long y, int m, int d) {
		long t1 = d;
		long t2 = (26 * (m + 1)) / 10;
		long t3 = y % 100 + (y % 100) / 4;
		long t4 = 5 * (y / 100) + (y / 100) / 4;
		return (t1 + t2 + t3 + t4) % 7;
	}
}
0