結果
問題 | No.87 Advent Calendar Problem |
ユーザー |
![]() |
提出日時 | 2014-12-07 02:32:14 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 132 ms / 5,000 ms |
コード長 | 1,097 bytes |
コンパイル時間 | 2,095 ms |
コンパイル使用メモリ | 74,532 KB |
実行使用メモリ | 41,560 KB |
最終ジャッジ日時 | 2024-06-11 16:01:26 |
合計ジャッジ時間 | 6,528 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
import java.util.*; public class Main { static boolean isLeapYear(long y) { return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0); } static long func(long n) { long cnt1 = 0; long LOOP = 400 * 7; long d = 0; for(int i = 1; i <= LOOP && 2014 + i <= n; i++) { d += isLeapYear(i + 2014) ? 2 : 1; if(d % 7 == 0) cnt1++; if(2014 + i == n) { return cnt1; } } long ans = (n - 2015) / LOOP * cnt1; d = d % 7 * (n - 2015) / LOOP % 7; for(long i = (n - 2015) / LOOP * LOOP + 2015; i <= n; i++) { d += isLeapYear(i) ? 2 : 1; if(d % 7 == 0) ans++; } return ans; } public static void main(String[] args) { /* for(int i = 2015; i <= 10000; i++) { int ans = 0; int d = 0; for(int j = 2015; j <= i; j++) { d += isLeapYear(j) ? 2 : 1; if(d % 7 == 0) ans++; } if(ans != func(i)) { System.err.println(i + " " + ans + " " + func(i)); } } if(true) return; */ try(final Scanner sc = new Scanner(System.in)) { System.out.println(func(sc.nextLong())); } } }