結果
問題 |
No.3114 0→1
|
ユーザー |
|
提出日時 | 2025-04-20 04:23:59 |
言語 | C++17(gnu拡張) (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,620 bytes |
コンパイル時間 | 824 ms |
コンパイル使用メモリ | 71,304 KB |
実行使用メモリ | 19,904 KB |
最終ジャッジ日時 | 2025-04-20 04:24:06 |
合計ジャッジ時間 | 7,334 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | TLE * 1 -- * 29 |
ソースコード
#include <iostream> #include <string> #include <vector> using namespace std; bool isGoodString(const string& s) { for (int len = 2; len <= s.size(); len++) { for (int start = 0; start + len <= s.size(); start++) { int zeros = 0, ones = 0; for (int i = start; i < start + len; i++) { if (s[i] == '0') zeros++; else ones++; } if (zeros < ones) { return false; } } } return true; } int minOperations(string s) { int n = s.size(); int operations = 0; while (!isGoodString(s)) { bool found = false; for (int len = 2; len <= n && !found; len++) { for (int start = 0; start + len <= n && !found; start++) { int zeros = 0, ones = 0; for (int i = start; i < start + len; i++) { if (s[i] == '0') zeros++; else ones++; } if (zeros < ones) { for (int i = 0; i < n; i++) { if (s[i] == '0') { s[i] = '1'; operations++; found = true; break; } } } } } if (!found) break; } return operations; } int main() { int n; cin >> n; string s; cin >> s; cout << minOperations(s) << endl; return 0; }