結果

問題 No.1765 While Shining
ユーザー ks2mks2m
提出日時 2021-11-26 22:36:02
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 740 bytes
コンパイル時間 2,836 ms
コンパイル使用メモリ 73,780 KB
実行使用メモリ 66,528 KB
最終ジャッジ日時 2023-09-12 05:14:03
合計ジャッジ時間 14,761 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
55,820 KB
testcase_01 AC 124 ms
53,980 KB
testcase_02 AC 123 ms
55,944 KB
testcase_03 RE -
testcase_04 AC 144 ms
55,608 KB
testcase_05 AC 170 ms
56,184 KB
testcase_06 AC 158 ms
55,924 KB
testcase_07 AC 138 ms
55,656 KB
testcase_08 AC 181 ms
56,688 KB
testcase_09 AC 509 ms
60,692 KB
testcase_10 AC 596 ms
64,940 KB
testcase_11 AC 577 ms
62,836 KB
testcase_12 AC 573 ms
64,336 KB
testcase_13 AC 540 ms
62,240 KB
testcase_14 AC 591 ms
66,528 KB
testcase_15 AC 592 ms
65,196 KB
testcase_16 AC 589 ms
65,060 KB
testcase_17 AC 581 ms
64,356 KB
testcase_18 AC 587 ms
65,064 KB
testcase_19 AC 596 ms
64,848 KB
testcase_20 AC 591 ms
65,928 KB
testcase_21 AC 581 ms
64,732 KB
testcase_22 AC 591 ms
65,288 KB
testcase_23 AC 591 ms
62,952 KB
testcase_24 AC 583 ms
64,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		long[] num = new long[n + 1];
		num[1] = 1;
		num[2] = 2;
		for (int i = 3; i < num.length; i++) {
			num[i] = num[i - 2] + i;
		}

		long ans = 0;
		int cnt = 0;
		for (int i = 0; i < n - 1; i++) {
			if (cnt % 2 == 0) {
				if (a[i] == 1) {
					cnt++;
				} else {
					ans += num[cnt];
					cnt = 0;
				}
			} else {
				if (a[i] == 1) {
					ans += num[cnt];
					cnt = 1;
				} else {
					cnt++;
				}
			}
		}
		ans += num[cnt];
		System.out.println(ans);
	}
}
0