結果

問題 No.87 Advent Calendar Problem
ユーザー GrenacheGrenache
提出日時 2015-11-22 17:40:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 123 ms / 5,000 ms
コード長 1,140 bytes
コンパイル時間 5,245 ms
コンパイル使用メモリ 73,980 KB
実行使用メモリ 39,476 KB
最終ジャッジ日時 2023-10-11 18:15:29
合計ジャッジ時間 10,335 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
39,112 KB
testcase_01 AC 114 ms
39,232 KB
testcase_02 AC 115 ms
39,276 KB
testcase_03 AC 116 ms
39,340 KB
testcase_04 AC 113 ms
39,172 KB
testcase_05 AC 115 ms
39,268 KB
testcase_06 AC 118 ms
39,208 KB
testcase_07 AC 116 ms
39,476 KB
testcase_08 AC 114 ms
39,216 KB
testcase_09 AC 114 ms
39,256 KB
testcase_10 AC 116 ms
39,076 KB
testcase_11 AC 115 ms
39,264 KB
testcase_12 AC 113 ms
39,044 KB
testcase_13 AC 116 ms
39,148 KB
testcase_14 AC 117 ms
39,184 KB
testcase_15 AC 112 ms
39,272 KB
testcase_16 AC 123 ms
39,240 KB
testcase_17 AC 112 ms
39,084 KB
testcase_18 AC 113 ms
39,240 KB
testcase_19 AC 114 ms
39,288 KB
testcase_20 AC 117 ms
39,148 KB
testcase_21 AC 114 ms
39,340 KB
testcase_22 AC 115 ms
39,136 KB
testcase_23 AC 113 ms
39,448 KB
testcase_24 AC 114 ms
39,192 KB
testcase_25 AC 113 ms
39,144 KB
testcase_26 AC 115 ms
39,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder87 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long n = sc.nextLong();

        int ret = 0;
        long tmp = 0;
        for (long i = 2015; i <= Math.min(2400, n); i++) {
        	if ((i % 4 == 0 && i % 100 != 0) || (i % 4 == 0 && i % 400 == 0)) {
        		tmp += 2;
        	} else {
        		tmp += 1;
        	}

        	if (tmp % 7 == 0) {
        		ret++;
        	}
        }

        if (n > 2400) {
        	int[] wed = new int[400 + 1];
        	for (long i = 2401; i <= 2800; i++) {
            	if ((i % 4 == 0 && i % 100 != 0) || (i % 4 == 0 && i % 400 == 0)) {
            		tmp += 2;
            	} else {
            		tmp += 1;
            	}

            	if (tmp % 7 == 0) {
            		wed[(int)(i - 2400)] = wed[(int)(i - 1 - 2400)] + 1;
            	} else {
            		wed[(int)(i - 2400)] = wed[(int)(i - 1 - 2400)];
            	}
        	}

        	ret += (n - 2400) / 400 * wed[400] + wed[(int)((n - 2400) % 400)];
        }

        System.out.println(ret);

        sc.close();
    }
}
0