結果
| 問題 | No.3015 右に寄せろ! |
| コンテスト | |
| ユーザー |
Jikky1618
|
| 提出日時 | 2025-01-25 13:56:59 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,100 bytes |
| 記録 | |
| コンパイル時間 | 3,487 ms |
| コンパイル使用メモリ | 281,808 KB |
| 実行使用メモリ | 14,752 KB |
| 最終ジャッジ日時 | 2025-01-25 23:03:20 |
| 合計ジャッジ時間 | 5,083 ms |
|
ジャッジサーバーID (参考情報) |
judge7 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 WA * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...)
#endif
vector<pair<char, int>> run_length_encodeing(const string& S) {
vector<pair<char, int>> res;
for (auto c : S) {
if (!res.empty() && c == res.back().first) {
res.back().second++;
} else {
res.emplace_back(c, 1);
}
}
return res;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
string S;
cin >> S;
auto res = run_length_encodeing(S);
int ans = 0;
stack<pair<char, int>> stk;
for (auto&& [c, cnt] : res) {
if (!stk.empty() && stk.top().first == '1' && c == '0') {
auto [c2, cnt2] = stk.top();
ans += cnt2 / 2;
cnt--;
}
if (stk.empty()) {
stk.emplace(c, cnt);
} else if (stk.top().first == c) {
stk.top().second += cnt;
} else if (cnt > 0) {
stk.emplace(c, cnt);
}
}
cout << ans << endl;
}
Jikky1618