結果

問題 No.2924 <===Super Spaceship String===>
ユーザー eve__fuyuki
提出日時 2024-10-12 18:33:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 892 bytes
コンパイル時間 2,164 ms
コンパイル使用メモリ 197,756 KB
最終ジャッジ日時 2025-02-24 18:54:04
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 7 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

void fast_io() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
}

int main() {
	fast_io();
	string s;
	cin >> s;
	vector<pair<char, int>> rle;
	for (int i = 0; i < s.size(); i++) {
		if (rle.empty() || rle.back().first != s[i]) {
			rle.push_back({s[i], 1});
		} else {
			rle.back().second++;
		}
	}
	int l = rle.size();
	vector<pair<char, int>> st;
	for (auto [c, cnt] : rle) {
		if (c == '>' && st.size() > 1 && st.back().first == '=' &&
			st[st.size() - 2].first == '<') {
			st.pop_back();
			st.back().second--;
			if (st.back().second == 0) {
				st.pop_back();
			}
			if (cnt > 1) {
				st.push_back({c, cnt - 1});
			}
		} else if (st.empty() || c != st.back().first) {
			st.push_back({c, cnt});
		} else {
			st.back().second += cnt;
		}
	}
	int ans = 0;
	for (auto [c, cnt] : st) {
		ans += cnt;
	}
	cout << ans << endl;
}
0