結果

問題 No.457 (^^*)
ユーザー masamasa
提出日時 2017-02-16 22:12:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 957 bytes
コンパイル時間 539 ms
コンパイル使用メモリ 70,824 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-28 17:48:01
合計ジャッジ時間 1,762 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 35 ms
4,380 KB
testcase_13 AC 54 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 34 ms
4,380 KB
testcase_16 AC 53 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 RE -
testcase_19 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
	string s;
	cin >> s;

	s = s.substr(s.find('('));
	s = s.substr(0, s.rfind(')') + 1);

	int n = s.size();
	vector<int> closes(n + 1 , 0);
	for (int i = n - 1; i >= 0; i--) {
		closes[i] = closes[i + 1];
		if (s[i] == ')') {
			closes[i]++;
		}
	}

	const string sl = "(^^*)";
	const string sr = "(*^^)";

	int l_count = 0;
	int r_count = 0;

	for (int i = 0; i < n; i++) {
		if (s[i] != '(') {
			continue;
		}

		int l_idx = 1;
		int r_idx = 1;
		for (int j = i + 1; j < n; j++) {
			if (l_idx <= 3 && s[j] == sl[l_idx]) {
				l_idx++;
				if (l_idx == 4) {
					l_count += closes[j];
					if (r_idx == 4) {
						break;
					}
				}
			}

			if (r_idx <= 3 && s[j] == sr[r_idx]) {
				r_idx++;
				if (r_idx == 4) {
					r_count += closes[j];
					if (l_idx == 4) {
						break;
					}
				}
			}
		}
	}

	cout << l_count << " " << r_count << endl;
	return 0;
}
0