結果

問題 No.457 (^^*)
ユーザー GrenacheGrenache
提出日時 2016-12-08 00:24:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 396 ms / 2,000 ms
コード長 1,521 bytes
コンパイル時間 5,260 ms
コンパイル使用メモリ 77,436 KB
実行使用メモリ 59,024 KB
最終ジャッジ日時 2023-08-18 20:46:27
合計ジャッジ時間 9,862 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
55,548 KB
testcase_01 AC 123 ms
55,780 KB
testcase_02 AC 117 ms
55,536 KB
testcase_03 AC 122 ms
56,056 KB
testcase_04 AC 119 ms
55,780 KB
testcase_05 AC 125 ms
55,528 KB
testcase_06 AC 125 ms
55,936 KB
testcase_07 AC 146 ms
55,576 KB
testcase_08 AC 154 ms
56,168 KB
testcase_09 AC 180 ms
56,076 KB
testcase_10 AC 212 ms
56,408 KB
testcase_11 AC 250 ms
58,436 KB
testcase_12 AC 386 ms
58,904 KB
testcase_13 AC 204 ms
59,024 KB
testcase_14 AC 176 ms
56,920 KB
testcase_15 AC 396 ms
58,696 KB
testcase_16 AC 196 ms
58,744 KB
testcase_17 AC 171 ms
56,400 KB
testcase_18 AC 118 ms
56,368 KB
testcase_19 AC 118 ms
55,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder457 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		char[] s = sc.next().toCharArray();

		TreeSet<Integer> tsl = new TreeSet<>();
		TreeSet<Integer> tsr = new TreeSet<>();
		TreeSet<Integer> tsh = new TreeSet<>();
		TreeSet<Integer> tsa = new TreeSet<>();
		for (int i = 0, size = s.length; i < size; i++) {
			if (s[i] == '(') {
				tsl.add(i);
			}
			if (s[i] == ')') {
				tsr.add(i);
			}
			if (s[i] == '^') {
				tsh.add(i);
			}
			if (s[i] == '*') {
				tsa.add(i);
			}
		}

		int retl = 0;
		for (int l : tsl) {
			Integer tmp = tsh.higher(l);
			if (tmp == null) {
				continue;
			}
			tmp = tsh.higher(tmp);
			if (tmp == null) {
				continue;
			}
			tmp = tsa.higher(tmp);
			if (tmp == null) {
				continue;
			}
			retl += tsr.tailSet(tmp).size();
		}

		int retr = 0;
		for (int l : tsl) {
			Integer tmp = tsa.higher(l);
			if (tmp == null) {
				continue;
			}
			tmp = tsh.higher(tmp);
			if (tmp == null) {
				continue;
			}
			tmp = tsh.higher(tmp);
			if (tmp == null) {
				continue;
			}
			retr += tsr.tailSet(tmp).size();
		}

		pr.printf("%d %d\n", retl, retr);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0