結果
| 問題 | No.1765 While Shining |
| コンテスト | |
| ユーザー |
ks2m
|
| 提出日時 | 2021-11-26 22:36:02 |
| 言語 | Java (openjdk 23) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 740 bytes |
| 記録 | |
| コンパイル時間 | 1,831 ms |
| コンパイル使用メモリ | 77,336 KB |
| 実行使用メモリ | 63,668 KB |
| 最終ジャッジ日時 | 2024-06-29 18:14:39 |
| 合計ジャッジ時間 | 12,876 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 RE * 1 |
ソースコード
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);
}
}
ks2m