結果

問題 No.457 (^^*)
ユーザー t98slidert98slider
提出日時 2022-12-29 23:24:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,109 bytes
コンパイル時間 1,906 ms
コンパイル使用メモリ 171,208 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-16 10:06:51
合計ジャッジ時間 3,251 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    vector<ll> cum(n + 1), ls(n + 1), rs(n + 1);
    vector<int> pos;
    pos.push_back(-1);
    for(int i = 0; i < n; i++){
        ls[i + 1] = ls[i] + (s[i] == '(');
        rs[i + 1] = rs[i] + (s[i] == ')');
        cum[i + 1] = cum[i] + (s[i] == '^');
        if(s[i] == '*')pos.push_back(i);
    }
    pos.push_back(n + 1);
    ll ans1 = 0, ans2 = 0;
    for(int l = 0, r = 0, id = 0; l < n; l++){
        if(s[l] != '(')continue;
        r = max(r, l);
        while(r <= n && cum[r] - cum[l] < 2)r++;
        while(pos[id] < r)id++;
        if(pos[id] == n + 1)break;
        ans2 += rs[n] - rs[pos[id]];
    }
    for(int l = n, r = n, id = pos.size() - 1; r >= 1; r--){
        if(s[r - 1] != ')')continue;
        l = min(l, r);
        while(l >= 0 && cum[r] - cum[l] < 2)l--;
        while(pos[id] > l)id--;
        if(pos[id] == -1)break;
        ans1 += ls[pos[id]];
    }
    cout << ans2 << " " << ans1 << endl;
}
0