結果
| 問題 | No.87 Advent Calendar Problem |
| コンテスト | |
| ユーザー |
uafr_cs
|
| 提出日時 | 2015-08-17 02:35:23 |
| 言語 | Java (openjdk 25.0.1) |
| 結果 |
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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 1 WA * 23 |
ソースコード
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);
}
}
uafr_cs