結果

問題 No.2924 <===Super Spaceship String===>
ユーザー Nzt3
提出日時 2024-10-19 17:40:17
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 989 bytes
コンパイル時間 1,987 ms
コンパイル使用メモリ 196,992 KB
最終ジャッジ日時 2025-02-24 21:36:56
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr int MOD=998244353;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,l,r) for(int i=(l);i<(int)(r);i++)
#define all(v) v.begin(),v.end()

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  cin>>S;
  int ans=S.size();
  stack<pair<char,int>,vector<pair<char,int>>> memo;
  for(auto i:S){
    if(i=='<'){
      memo.push({'<',1});
    }else if(i=='='){
      if(!memo.empty()&&memo.top().first=='='){
        memo.top().second+=1;
      }else{
        memo.push({'=',1});
      }
    }else if(i=='>'){
      if(memo.size()>=2){
        auto b=memo.top();
        memo.pop();
        auto a=memo.top();
        memo.pop();
        if(a.first=='<'&&b.first=='='){
          ans-=a.second+b.second+1;
        }else{
          memo.push(a);
          memo.push(b);
          memo.push({'>',1});
        }
      }else{
        memo.push({'>',1});
      }
    }
  }
  cout<<ans<<'\n';
}
0