-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCF_1430D.cpp
More file actions
49 lines (45 loc) · 862 Bytes
/
CF_1430D.cpp
File metadata and controls
49 lines (45 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <functional>
#include <cstdlib>
#include <list>
#include <iomanip>
#define ll long long
using namespace std;
int main() {
int T;
cin >> T;
for (int t = 0; t < T; t++) {
int n;
string s;
cin >> n >> s;
s.push_back('X'); // dummy
int cnt = 1;
int dead = 0;
int total = 0;
for (int i = 1; i < s.size(); i++) {
if (s[i] == s[i - 1]) {
cnt++;
}
else {
if (cnt == 1) {
dead++;
} else if (cnt > 2) {
dead = max(dead - (cnt - 2), 0);
}
total++;
cnt = 1;
}
}
cout << "total: " << total << endl;
cout << "dead: " << dead << endl;
cout << "ans: " << total - (dead/2) << endl;
}
}