Skip to content

Commit c66082b

Browse files
committed
codeforces 391
1 parent c60596c commit c66082b

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

CodeForces/391/A.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <iostream>
2+
#include <string>
3+
using namespace std;
4+
5+
#define REP(i,n) for(int i=0;i<(n);++i)
6+
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
7+
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
8+
9+
int main() {
10+
string str;
11+
cin >> str;
12+
int n = 1, res = 0;
13+
char ch = str[0];
14+
FOR(i,1,str.length()-1) {
15+
if (str[i] == ch) ++n;
16+
else {
17+
if ((n & 1) == 0) ++res;
18+
n = 1;
19+
ch = str[i];
20+
}
21+
}
22+
if ((n & 1) == 0) ++res;
23+
cout << res << endl;
24+
return 0;
25+
}

CodeForces/391/B.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <vector>
4+
using namespace std;
5+
6+
#define REP(i,n) for(int i=0;i<(n);++i)
7+
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
8+
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
9+
10+
int main() {
11+
string str;
12+
cin >> str;
13+
vector<vector<int> > mm(26, vector<int>());
14+
REP(i,str.length()) mm[str[i] - 'A'].push_back(i);
15+
int res = 1;
16+
REP(i,26) {
17+
if (mm[i].empty()) continue;
18+
REP(j,mm[i].size()) {
19+
int st = mm[i][j];
20+
int n = 1;
21+
FOR(k,j+1,mm[i].size()-1) {
22+
int d = mm[i][k] - st;
23+
if (d & 1) {
24+
++n;
25+
st = mm[i][k];
26+
}
27+
}
28+
res = max(res, n);
29+
}
30+
}
31+
cout << res << endl;
32+
return 0;
33+
}

0 commit comments

Comments
 (0)