結果

問題 No.457 (^^*)
ユーザー 37zigen37zigen
提出日時 2016-12-08 17:49:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 1,286 bytes
コンパイル時間 4,337 ms
コンパイル使用メモリ 75,820 KB
実行使用メモリ 57,176 KB
最終ジャッジ日時 2023-08-19 02:29:46
合計ジャッジ時間 7,893 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
57,176 KB
testcase_01 AC 137 ms
56,764 KB
testcase_02 AC 140 ms
56,740 KB
testcase_03 AC 147 ms
56,848 KB
testcase_04 AC 144 ms
56,820 KB
testcase_05 AC 139 ms
56,780 KB
testcase_06 AC 139 ms
56,920 KB
testcase_07 AC 142 ms
56,716 KB
testcase_08 AC 144 ms
56,880 KB
testcase_09 AC 152 ms
56,792 KB
testcase_10 AC 176 ms
56,676 KB
testcase_11 AC 184 ms
56,380 KB
testcase_12 AC 185 ms
56,808 KB
testcase_13 AC 187 ms
56,940 KB
testcase_14 AC 192 ms
56,616 KB
testcase_15 AC 179 ms
56,500 KB
testcase_16 AC 181 ms
56,944 KB
testcase_17 AC 182 ms
56,604 KB
testcase_18 AC 139 ms
56,764 KB
testcase_19 AC 142 ms
56,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.*;

public class Q457 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		int n = s.length();
		int[] ans=new int[2];
		for (int x = 0; x < 2; ++x) {
			int[] c = new int[n];
			for (int i = n - 1; i >= 0; --i) {
				if (i != n - 1)
					c[i] = c[i + 1];
				if (s.charAt(i) == ')')
					++c[i];
			}

			int[] dp1 = new int[n];
			int[] dp2 = new int[n];
			int pre = n;
			int cur = n;
			for (int i = n - 1; i >= 0; --i) {
				if (s.charAt(i) == '^') {
					pre = cur;
					cur = i;
				}
				dp1[i] = pre;
			}
			pre = n;
			for (int i = n - 1; i >= 0; --i) {
				if (s.charAt(i) == '*')
					pre = i;
				dp2[i] = pre;
			}
			for (int i = 0; i < n; ++i) {
				if (s.charAt(i) == '(') {
					int p = dp2[i];
					if (p == n)
						continue;
					p = dp1[p];
					if (p == n)
						continue;
					ans[x] += c[p];
				}
			}
			s = reverse(s);
		}
		System.out.println(ans[1]+" "+ans[0]);
	}

	static String reverse(String s) {
		StringBuilder sb = new StringBuilder();
		for (int i = s.length() - 1; i >= 0; --i) {
			if (s.charAt(i) == '(')
				sb.append(')');
			else if (s.charAt(i) == ')')
				sb.append('(');
			else
				sb.append(s.charAt(i));
		}
		return sb.toString();
	}
}
0