結果

問題 No.2924 <===Super Spaceship String===>
ユーザー momoyuu
提出日時 2024-10-13 17:39:24
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,134 bytes
コンパイル時間 906 ms
コンパイル使用メモリ 96,624 KB
実行使用メモリ 8,532 KB
最終ジャッジ日時 2024-10-16 17:56:15
合計ジャッジ時間 1,572 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
using ll = long long;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    string s;
    cin>>s;
    vector<pair<int,int>> st;
    int n = s.size();
    for(int i = 0;i<n;i++){
        if(st.empty()){
            if(s[i]=='<') st.push_back(make_pair(1,1));
            else st.push_back(make_pair(-1,1));
        }else{
            auto now = st.back();
            if(s[i]=='<') st.push_back(make_pair(1,1));
            else if(s[i]=='='){
                if(now.first==1) {
                    st.back().first = 2;
                    st.back().second++;
                }else if(now.first==2){
                    st.back().second++;
                }else{
                    st.push_back(make_pair(-1,1));
                }
            }else{
                if(now.first==2){
                    st.pop_back();
                }else{
                    st.push_back(make_pair(-1,1));
                }
            }
        }
    }
    int ans = 0;
    for(int i = 0;i<st.size();i++) ans += st[i].second;
    cout<<ans<<endl;
}
0