結果
問題 | No.3114 0→1 |
ユーザー |
![]() |
提出日時 | 2025-04-18 23:51:44 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 756 bytes |
コンパイル時間 | 5,568 ms |
コンパイル使用メモリ | 332,340 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-04-18 23:51:56 |
合計ジャッジ時間 | 6,280 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; #define FAST_IO \ ios::sync_with_stdio(false); \ cin.tie(0); const i64 INF = 1001001001001001001; using Modint = atcoder::static_modint<998244353>; int main() { FAST_IO int N; cin >> N; string S; cin >> S; auto ans = 0; int mx = 0; int sl = 0; int sr = S[0] == '1' ? 1 : -1; int msl = 0; for (int i = 1; i < N; i ++) { sr += S[i] == '1' ? 1 : -1; int cur = sr - msl; if (cur < 0) { S[i] = '1'; sr += 2; ans ++; } sl += S[i - 1] == '1' ? 1 : -1; msl = max(msl, sl); } cout << ans << endl; }