結果

問題 No.457 (^^*)
ユーザー ytftytft
提出日時 2021-04-02 14:59:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,099 bytes
コンパイル時間 1,530 ms
コンパイル使用メモリ 167,416 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 23:14:24
合計ジャッジ時間 2,641 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
void calc(string S){
    int N=S.size();
    vector<int> nearest(N);
    int temp=N;
    for(int i=N-1;i>=0;i--){
        if(S[i]=='*'){
            temp=i;
        }
        nearest[i]=temp;
    }
    vector<int> nearest2(N);
    int temp2=N;
    temp=N;
    for(int i=N-1;i>=0;i--){
        if(S[i]=='^'){
            temp2=temp;
            temp=i;
        }
        nearest2[i]=temp2;
    }
    vector<int> nearest_merge(N);
    for(int i=0;i<N;i++){
        if(nearest[i]==N){
            nearest_merge[i]=N;
        }else{
            nearest_merge[i]=nearest2[nearest[i]];
        }
    }
    vector<int> end(N);
    temp=0;
    for(int i=N-1;i>=0;i--){
        if(S[i]==')'){
            ++temp;
        }
        end[i]=temp;
    }
    int ret=0;
    for(int i=0;i<N;i++){
        if(S[i]=='(' && nearest_merge[i]!=N){
            ret+=end[nearest_merge[i]];
        }
    }
    cout<<ret;
}

int main(){
    string S,T;
    cin>>S;
    T="";
    for(int i=S.size()-1;i>=0;i--){
        T+=S[i];
    }
    calc(T);
    cout<<" ";
    calc(S);
}
0