結果

問題 No.87 Advent Calendar Problem
ユーザー uafr_csuafr_cs
提出日時 2015-08-17 02:35:23
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,764 bytes
コンパイル時間 2,065 ms
コンパイル使用メモリ 77,212 KB
実行使用メモリ 41,704 KB
最終ジャッジ日時 2024-07-18 09:57:04
合計ジャッジ時間 7,354 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 107 ms
40,908 KB
testcase_04 AC 110 ms
41,704 KB
testcase_05 AC 128 ms
41,164 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 104 ms
41,448 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	
	public static long simulate_count(final long begin, final long end, final int init_days, final int correct){
		int days = init_days;
		long count = 0;
		
		for(long year = begin; year < end; year++){
			if(year % 400 == 0){
				days += 2;
			}else if(year % 100 == 0){
				days += 1;
			}else if(year % 4 == 0){
				days += 2;
			}else{
				days += 1;
			}
			
			days %= 7;
			
			if(days == correct){ count++; }
		}
		
		return count;
	}
	
	public static long simulate_days(final long begin, final long end, final int init_days, final int correct){
		int days = init_days;
		long count = 0;
		
		for(long year = begin; year < end; year++){
			if(year % 400 == 0){
				days += 2;
			}else if(year % 100 == 0){
				days += 1;
			}else if(year % 4 == 0){
				days += 2;
			}else{
				days += 1;
			}
			
			days %= 7;
			
			if(days == correct){ count++; }
		}
		
		return days;
	}
	
	
	
	// [year)
	public static void simulation(final int initial_days, final int correct_days, final long year, int[] nexts, long[] counts){
		int days = initial_days;
		
		long count = 0;
		for(long i = 0; i < year; i++){
			if(i % 400 == 0){
				days += 2;
			}else if(i % 100 == 0){
				days += 1;
			}else if(i % 4 == 0){
				days += 2;
			}else{
				days += 1;
			}
			
			days %= 7;
			
			if(days == correct_days){ count++; }
		}
		
		nexts[initial_days] = days;
		counts[initial_days] = count;
	}
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		final long N = sc.nextLong();
		
		final int correct_days = 3;
		int days = 3;
		
		long[] counts_1   = new long[7];
		long[] counts_4   = new long[7];
		long[] counts_100 = new long[7];
		long[] counts_400 = new long[7];
		int[] nexts_1    = new int[7];
		int[] nexts_4    = new int[7];
		int[] nexts_100  = new int[7];
		int[] nexts_400  = new int[7];
		
		for(int d = 0; d < 7; d++){
			simulation(d, correct_days, 1,   nexts_1,   counts_1);
			simulation(d, correct_days, 4,   nexts_4,   counts_4);
			simulation(d, correct_days, 100, nexts_100, counts_100);
			simulation(d, correct_days, 400, nexts_400, counts_400);
		}
		
		long answer = 0;
		for(long year = 2015; year <= N; ){
			//System.out.println(year + " " + answer);
			
			if(year % 400 == 0 && ((year + 400) <= N)){
				answer += counts_400[days];
				days = nexts_400[days];
				year += 400;
			}else if(year % 100 == 0 && ((year + 100)) <= N){
				answer += counts_100[days];
				days = nexts_100[days];
				year += 100;
			}else if(year % 4 == 0 && ((year + 4) <= N)){
				answer += counts_4[days];
				days = nexts_4[days];
				year += 4;
			}else{
				answer += counts_1[days];
				days = nexts_1[days];
				year += 1;
			}
		}
		
		System.out.println(answer);
	}
	
}
0