結果
| 問題 | No.2924 <===Super Spaceship String===> |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-19 17:40:17 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 2,000 ms |
| コード長 | 989 bytes |
| 記録 | |
| コンパイル時間 | 1,080 ms |
| コンパイル使用メモリ | 216,612 KB |
| 実行使用メモリ | 9,200 KB |
| 最終ジャッジ日時 | 2026-07-06 00:41:06 |
| 合計ジャッジ時間 | 2,201 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 12 |
ソースコード
#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';
}