結果
| 問題 |
No.457 (^^*)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-20 19:45:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 47 ms / 2,000 ms |
| コード長 | 2,510 bytes |
| コンパイル時間 | 1,878 ms |
| コンパイル使用メモリ | 167,144 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-14 11:36:44 |
| 合計ジャッジ時間 | 2,855 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
#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;
//}
int left_calc() {
int 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;
}
int right_calc() {
int 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;
}