結果
| 問題 |
No.457 (^^*)
|
| コンテスト | |
| ユーザー |
ebicochineal
|
| 提出日時 | 2016-12-08 23:34:16 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,036 bytes |
| コンパイル時間 | 1,928 ms |
| コンパイル使用メモリ | 177,164 KB |
| 実行使用メモリ | 10,496 KB |
| 最終ジャッジ日時 | 2024-11-28 15:34:26 |
| 合計ジャッジ時間 | 15,855 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 TLE * 4 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
string replace5126(string str, string old_s, string new_s, int n = 0) {
n = n < 1 ? str.size() : n;
for (int i; (i = str.find(old_s)) > -1 && n; --n) { str.replace(i, old_s.size(), new_s); }
return str;
}
int count5126(string str, string a) {
int cnt = 0;
for (int i = 0; (i = str.find(a, i)) > -1; i += a.size()) { ++cnt; }
return cnt;
}
vector<string> split5126(string str, string sep = " ", int n = 0) {
int prev = 0;
vector<string> v;
n = n < 1 ? str.size() : n;
for (int i = 0; (i = str.find(sep, prev)) > -1 && n; --n) {
v.push_back(str.substr(prev, i - prev));
prev = i + sep.size();
}
v.push_back(str.substr(prev, str.size()));
return v;
}
vector<string> rsplit5126(string str, string sep = " ", int n = 0) {
int prev = str.size() - 1;
vector<string> v;
n = n < 1 ? str.size() : n;
for (int i = 0; (i = str.rfind(sep, prev)) > -1 && n; --n) {
v.insert(v.begin(), str.substr(i + sep.size(), prev-i + sep.size() - 1));
prev = i - 1;
}
v.insert(v.begin(), str.substr(0, prev+1));
return v;
}
string slice5126(string str, int a, int b) {
int s = a < 0 ? str.size() + a : a;
int e = b < 0 ? str.size() + b : b;
e = b == 0 ? str.size() : e;
return str.substr(s, (s > e ? s : e) - s);
}
int main() {
string S;
int lcnt = 0, rcnt = 0;
cin >> S;
vector<int> l, r;
for (int i = 0; i < S.size(); ++i) {
if (S[i] == '(') { l.push_back(i); }
if (S[i] == ')') { r.push_back(i); }
}
string i;
for (auto& s : l) {
for (auto& e : r) {
if (s < e) {
i = slice5126(S, s+1, e);
if ((int)i.find('*', 0) > -1) {
lcnt += count5126(rsplit5126(i, "*", 1)[0], "^") > 1?1:0;
rcnt += count5126(split5126(i, "*", 1)[1], "^") > 1?1:0;
}
}
}
}
cout << lcnt << " " << rcnt << endl;
return 0;
}
ebicochineal