ログインしてください。
提出 #24241836
ソースコード 拡げる
import java.util.*;
public class Main {
public static void main(String[] args) {
// 入力
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.next());
long[] a = new long[n];
long[] b = new long[n];
for (int i = 0; i < n; i++) {
a[i] = Long.parseLong(sc.next());
}
for (int i = 0; i < n; i++) {
b[i] = Long.parseLong(sc.next());
}
// 矛盾ケース
if (a[n - 1] != b[0]) {
System.out.println(0);
return;
}
// 左から歩く
// c[i] = h → i番目の山のありえる高さは h 通り
// c[i] = 0 → i番目の山のありえる高さは 1 通り
long[] c = new long[n];
c[0] = 0;
for (int i = 1; i < n; i++) {
c[i] = (a[i - 1] == a[i]) ? a[i] : 0;
}
// 右から歩く
// d[i] = h → i番目の山のありえる高さは h 通り
// d[i] = 0 → i番目の山のありえる高さは 1 通り
long[] d = new long[n];
d[n - 1] = 0;
for (int i = n - 2; 0 <= i; i--) {
d[i] = (b[i] == b[i + 1]) ? b[i] : 0;
}
// 確認用
// System.out.println(Arrays.toString(c));
// System.out.println(Arrays.toString(d));
// 推理
// e[i] = h → i番目の山のありえる高さは h 通り
long[] e = new long[n];
for (int i = 0; i < n; i++) {
if (c[i] == 0 || d[i] == 0) {
e[i] = 1;
if (c[i] == 0 && d[i] == 0 && a[i] != b[i]) {
System.out.println(0);
return;
}
if (c[i] == 0 && d[i] != 0 && a[i] > d[i]) {
System.out.println(0);
return;
}
if (c[i] != 0 && d[i] == 0 && c[i] < b[i]) {
System.out.println(0);
return;
}
} else {
e[i] = Math.min(c[i], d[i]);
}
}
// 確認用
// System.out.println(Arrays.toString(e));
// こたえ
long result = 1;
long mod = 1000000000 + 7;
for (int i = 0; i < n; i++) {
result *= e[i];
result %= mod;
}
System.out.println(result);
}
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | C - 二人のアルピニスト |
| ユーザ | tobi00604 |
| 言語 | Java (OpenJDK 11.0.6) |
| 得点 | 400 |
| コード長 | 1949 Byte |
| 結果 | AC |
| 実行時間 | 492 ms |
| メモリ | 61404 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 400 / 400 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt |
| All | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 0_000.txt | AC | 101 ms | 35380 KiB |
| 0_001.txt | AC | 108 ms | 35236 KiB |
| 0_002.txt | AC | 107 ms | 35312 KiB |
| 0_003.txt | AC | 101 ms | 35456 KiB |
| 1_004.txt | AC | 104 ms | 35380 KiB |
| 1_005.txt | AC | 107 ms | 35320 KiB |
| 1_006.txt | AC | 106 ms | 35328 KiB |
| 1_007.txt | AC | 112 ms | 35376 KiB |
| 1_008.txt | AC | 396 ms | 61404 KiB |
| 1_009.txt | AC | 414 ms | 59964 KiB |
| 1_010.txt | AC | 439 ms | 60704 KiB |
| 1_011.txt | AC | 492 ms | 60220 KiB |
| 1_012.txt | AC | 432 ms | 60452 KiB |
| 1_013.txt | AC | 431 ms | 60188 KiB |
| 1_014.txt | AC | 450 ms | 60680 KiB |
| 1_015.txt | AC | 414 ms | 60400 KiB |
| 1_016.txt | AC | 407 ms | 60668 KiB |
| 1_017.txt | AC | 417 ms | 60396 KiB |
| 1_018.txt | AC | 366 ms | 59820 KiB |
| 1_019.txt | AC | 366 ms | 59944 KiB |
| 1_020.txt | AC | 393 ms | 60040 KiB |