Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <unordered_map>
- #include <string>
- #include <map>
- #include <cmath>
- #include <algorithm>
- #include <set>
- #define ll long long
- #define len(v) (int)v.size()
- #define all(v) v.begin(), v.end()
- const ll maxn = 2e5 + 10;
- const int logn = 20;
- const ll inf = 1e9;
- const int mod = 1e9 + 7;
- using namespace std;
- int n;
- string s;
- string t;
- int f1(bool c) {
- t = "";
- for (int i = 0; i < len(s) - 1; i += 2) {
- if (s[i] != s[i + 1]) {
- if (c)
- t += "11";
- else
- t += "00";
- }
- else if (s[i] == '1') {
- c = true;
- t += s[i];
- t += s[i + 1];
- }
- else if (s[i] == '0') {
- c = false;
- t += s[i];
- t += s[i + 1];
- }
- }
- int bl = 0, curcnt = 0, curbl;
- if (t[0] == '0') curbl = 1;
- else curbl = 0;
- for (int i = 0; i < len(t); ++i) {
- if (t[i] - '0' == curbl)
- continue;
- else {
- bl++;
- curbl = t[i] - '0';
- }
- }
- //cout << t << endl;
- return bl;
- }
- void solve() {
- cin >> n;
- cin >> s;
- int ans = 0;
- for (int i = 0; i < n - 1; i += 2) {
- if (s[i] != s[i + 1])
- ++ans;
- }
- cout << ans << " " << min(f1(true), f1(false)) << endl;
- t = "";
- }
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int t; cin >> t;
- while (t--) {
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment