結果

問題 No.1765 While Shining
ユーザー 小野寺健
提出日時 2021-11-28 20:28:19
言語 Java
(openjdk 23)
結果
AC  
実行時間 402 ms / 2,000 ms
コード長 475 bytes
コンパイル時間 3,414 ms
コンパイル使用メモリ 74,828 KB
実行使用メモリ 59,364 KB
最終ジャッジ日時 2024-07-01 15:26:49
合計ジャッジ時間 11,689 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class No1765 {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = Integer.valueOf(scan.nextLine());
		String[] S = scan.nextLine().split(" ");
		scan.close();
		int m0 = 0, m1 = 0;
		long cnt = 0;
		for (int i = 0; i < N-1; i++) {
			if (S[i].equals("1")) {
				cnt += 1 + m1;
				m0 = 1 + m1;
				m1 = 0;
			} else {
				cnt += m0;
				m1 = m0;
				m0 = 0;
			}
		}
		System.out.println(cnt);
	}
}
0