結果
| 問題 |
No.3114 0→1
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-20 16:21:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 799 bytes |
| コンパイル時間 | 678 ms |
| コンパイル使用メモリ | 66,436 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-04-20 16:21:22 |
| 合計ジャッジ時間 | 2,313 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | WA * 30 |
ソースコード
#include <iostream>
#include <string>
using namespace std;
int min_operations_to_good_string(int N, const string& S) {
int zero_count = 0; // 現在までの0の数
int one_count = 0; // 現在までの1の数
int operations = 0; // 操作回数
for (char c : S) {
if (c == '0') {
zero_count++;
} else {
one_count++;
}
// `0` が `1` より多い場合、修正が必要
if (zero_count > one_count) {
operations++;
zero_count--; // 1つの `0` を `1` に変換
}
}
return operations;
}
int main() {
int N;
string S;
// 入力
cin >> N;
cin >> S;
// 結果の出力
cout << min_operations_to_good_string(N, S) << endl;
return 0;
}