結果
問題 |
No.2924 <===Super Spaceship String===>
|
ユーザー |
![]() |
提出日時 | 2024-10-13 03:43:57 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 18 ms / 2,000 ms |
コード長 | 1,255 bytes |
コンパイル時間 | 2,891 ms |
コンパイル使用メモリ | 252,200 KB |
実行使用メモリ | 6,632 KB |
最終ジャッジ日時 | 2024-10-16 17:56:15 |
合計ジャッジ時間 | 3,647 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 12 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #ifdef LOCAL #include <debug_print.hpp> #define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else #define debug(...) (static_cast<void>(0)) #endif int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); string S; cin >> S; int N = S.size(), ans = N; stack<pair<char, int>> stk; for (int i = 0; i < N; i++) { if (stk.empty()) { stk.emplace(S[i], 1); } else { if (S[i] == '=' && stk.top().first == '=') { stk.top().second++; } else { stk.emplace(S[i], 1); } } while (stk.size() >= 3) { auto [c3, cnt3] = stk.top(); stk.pop(); auto [c2, cnt2] = stk.top(); stk.pop(); auto [c1, cnt1] = stk.top(); stk.pop(); if (c1 == '<' && c2 == '=' && c3 == '>') { ans -= cnt2 + 2; } else { stk.emplace(c1, cnt1); stk.emplace(c2, cnt2); stk.emplace(c3, cnt3); break; } } } cout << ans << '\n'; }