結果

問題 No.457 (^^*)
ユーザー ebicochinealebicochineal
提出日時 2016-12-08 23:34:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,036 bytes
コンパイル時間 2,017 ms
コンパイル使用メモリ 174,504 KB
実行使用メモリ 8,756 KB
最終ジャッジ日時 2023-08-19 02:37:34
合計ジャッジ時間 6,046 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#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;
}
0