Wrong Answer
Code
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--) {
int N;
string S;
cin >> N >> S;
vector<int> segments;
int count = 0;
for (int i = 0; i < N; ++i) {
if (S[i] == '1') {
++count;
} else {
if (count > 0) {
segments.push_back(count);
}
count = 0;
}
}
if (count > 0) {
segments.push_back(count);
}
sort(segments.rbegin(), segments.rend());
int max_consecutive_1s = 0;
for (int i = 0; i < segments.size(); i += 2) {
max_consecutive_1s += segments[i];
}
cout << max_consecutive_1s << endl;
}
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1113 Fliping Game
- Contest
- Brain Booster #7
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2024-11-05 15:20:32
- Judged At
- 2024-11-11 02:30:51
- Judged By
- Score
- 5
- Total Time
- 23ms
- Peak Memory
- 568.0 KiB