結果
問題 |
No.3114 0→1
|
ユーザー |
|
提出日時 | 2025-04-20 08:57:47 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 8 ms / 2,000 ms |
コード長 | 732 bytes |
コンパイル時間 | 853 ms |
コンパイル使用メモリ | 81,132 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-04-20 08:57:50 |
合計ジャッジ時間 | 2,352 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <cmath> #include <iostream> #include <string> using namespace std; using ll = long long; int main() { int n; string s; cin >> n >> s; int ans = 0, zero = 0, one = 100; s += '1'; for (const auto c : s) { if (c == '0') { if (one == 1) { ans++; zero--; } zero++; one = 0; } else { const auto p = zero / 3; const auto q = zero % 3; ans += 2 * p; if (q == 2) { ans++; } if (q != 1) { one++; } zero = 0; one++; } } cout << ans << endl; return 0; }