結果

問題 No.457 (^^*)
ユーザー naimonon77naimonon77
提出日時 2016-12-20 19:43:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 2,506 bytes
コンパイル時間 1,492 ms
コンパイル使用メモリ 165,044 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-21 03:22:52
合計ジャッジ時間 2,650 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"

#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define LINF ((ll)1 << 60)
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
const int MAX = (int)2e5 + 5;

string s;

//ll left_calc() {
//	ll res = 0;
//	int hat_id = -1;
//	int star_id = -1;
//	int right_parenthesis_cnt = 0;
//	rep(i, s.size()) {
//		if (hat_id == -1 && s[i] == '^') hat_id = i;
//		if (hat_id != -1 && star_id != -1 && s[i] == '*') {
//			star_id = i;
//		}
//		if (s[i] == ')') right_parenthesis_cnt++;
//	}
//	rep(i, s.size()) {
//		if (s[i] == '^') {
//			REP(i, hat_id, s.size()) {
//				if (s[i] == '^') {
//					hat_id = i; break;
//				}
//			}
//			star_id = -1;
//			REP(i, hat_id, s.size()) {
//				if (s[i] == '*') {
//					star_id = i; break;
//				}
//			}
//		}
//		if (s[i] == )
//			if (s[i] == ')') right_parenthesis_cnt--;
//		if (s[i] == '(' && hat_id != -1 && star_id != 0) {
//			res += right_parenthesis_cnt;
//		}
//	}
//	return res;
//}

ll left_calc() {
	ll res = 0;
	rep(i, s.size()) {
		if (s[i] == '(') {
			int stage = 0;
		  int right_parenthesis_cnt = 0;
			REP(j, i, s.size()) {
				if (stage == 0 && s[j] == '^') stage = 1;
				else if (stage == 1 && s[j] == '^') stage = 2;
				else if (stage == 2 && s[j] == '*') stage = 3;
				else if (stage == 3 && s[j] == ')') {
					right_parenthesis_cnt++;
				}
			}
			res += right_parenthesis_cnt;
		}
	}
	return res;
}

ll right_calc() {
	ll res = 0;
	rep(i, s.size()) {
		if (s[i] == '(') {
			int stage = 0;
			int right_parenthesis_cnt = 0;
			REP(j, i, s.size()) {
				if (stage == 0 && s[j] == '*') stage = 1;
				else if (stage == 1 && s[j] == '^') stage = 2;
				else if (stage == 2 && s[j] == '^') stage = 3;
				else if (stage == 3 && s[j] == ')') {
					right_parenthesis_cnt++;
				}
			}
			res += right_parenthesis_cnt;
		}
	}
	return res;
}

void solve() {
	cin >> s;
	ll res_left = left_calc();
	ll res_right = right_calc();
	cout << res_left << " " << res_right << endl;
}

signed main() {
	cout << fixed << setprecision(20);
	rep(i, 1) solve();
	return 0;
}
0