結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー ks2mks2m
提出日時 2020-06-26 21:37:24
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,262 bytes
コンパイル時間 3,730 ms
コンパイル使用メモリ 81,216 KB
実行使用メモリ 84,180 KB
最終ジャッジ日時 2023-09-18 03:28:32
合計ジャッジ時間 12,604 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,668 KB
testcase_01 AC 44 ms
49,376 KB
testcase_02 AC 44 ms
49,428 KB
testcase_03 AC 46 ms
49,460 KB
testcase_04 WA -
testcase_05 AC 48 ms
49,304 KB
testcase_06 AC 46 ms
49,608 KB
testcase_07 AC 46 ms
49,504 KB
testcase_08 WA -
testcase_09 AC 46 ms
49,360 KB
testcase_10 WA -
testcase_11 AC 46 ms
49,580 KB
testcase_12 WA -
testcase_13 AC 108 ms
53,100 KB
testcase_14 AC 109 ms
51,652 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 106 ms
53,160 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 109 ms
53,624 KB
testcase_23 AC 573 ms
72,516 KB
testcase_24 WA -
testcase_25 AC 599 ms
72,160 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 605 ms
83,948 KB
testcase_29 AC 600 ms
84,180 KB
testcase_30 AC 629 ms
70,712 KB
testcase_31 AC 626 ms
72,668 KB
testcase_32 AC 635 ms
72,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		TreeMap<Integer, Integer> map = new TreeMap<>();
		for (int i = 0; i < n; i++) {
			map.put(a[i], i);
		}

		TreeSet<Integer> set = new TreeSet<>();
		boolean h = false;
		for (Integer k : map.keySet()) {
			if (set.size() == 0) {
			} else if (set.size() == 1) {
				if (set.last() < map.get(k)) {
					h = true;
				}
			} else {
				if (h && set.last() > map.get(k)) {
					int v1 = a[set.first()];
					int v2 = a[map.get(k)];
					int v3 = a[set.higher(map.get(k))];
					System.out.println(v1 + v2 + v3);
					return;
				}
				if (!h && set.first() < map.get(k)) {
					int v1 = a[set.last()];
					int v2 = a[map.get(k)];
					int v3 = a[set.lower(map.get(k))];
					System.out.println(v1 + v2 + v3);
					return;
				}
			}
			set.add(map.get(k));
		}
		System.out.println(-1);
	}
}
0