結果
問題 | No.2924 <===Super Spaceship String===> |
ユーザー |
|
提出日時 | 2024-10-28 23:58:29 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 21 ms / 2,000 ms |
コード長 | 1,046 bytes |
コンパイル時間 | 2,229 ms |
コンパイル使用メモリ | 198,804 KB |
最終ジャッジ日時 | 2025-02-25 01:12:57 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 12 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)s; i < (int)e; ++i) #define all(a) (a).begin(), (a).end() int main() { cin.tie(nullptr); string S; cin >> S; int siz = S.size(); stack<pair<char, int>> st; st.push({'a', 1}); st.push({'a', 1}); rep(i, 0, siz) { if (S[i] == '=') { if (st.top().first == '=') st.top().second++; else st.push({'=', 1}); } else if (S[i] == '>') { if (st.top().first == '=') { pair<char, int> tmp = st.top(); st.pop(); if (st.top().first == '<') st.pop(); else { st.push(tmp); st.push({'>', 1}); } } else st.push({'>', 1}); } else { st.push({'<', 1}); } } int ans = -2; while (!st.empty()) { ans += st.top().second; st.pop(); } cout << ans << '\n'; }