-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path451D.cpp
More file actions
106 lines (97 loc) · 1.82 KB
/
451D.cpp
File metadata and controls
106 lines (97 loc) · 1.82 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9+7;
const int mx = 1e7+2;
const int INF = 1e18;
int fact[mx];
int binpow(int a,int n)
{
if(!n) return 1;
if(n==1) return a;
if(n%2==1) return a*binpow(a,n-1);
else
{
int t = binpow(a,n/2);
return t*t;
}
}
int inverse(int x)
{
return binpow(x,mod-2);
}
int div_mod(int a, int b)
{
return a*inverse(b)%mod;
}
int cnk(int n, int k)
{
if(n<k) return 0;
return div_mod(fact[n],fact[k]*fact[n-k]%mod);
}
int gcd(int a, int b)
{
if(!b)return a;
return gcd(b,a%b);
}
int sum(int l, int r,vector<int>&a)
{
if(l > r) return 0;
if(!l) return a[r];
return (a[r]-a[l-1]+mod)%mod;
}
main()
{
int n,ans1 = 0, ans2=0,cnt0=0,cnt1=0,j=0;
string s;
cin >> s;
n=s.size();
int last = -1;
for(int i = 0; i < n; i++) {
if(s[i]=='a'&&last==-1) {
last=i;
ans1++;
continue;
}
if(s[i]=='a'){
j++;
if(i%2!=last%2){
swap(cnt0,cnt1);
}
if((i-last+1)%2==0){
cnt0++;
}
else cnt1++;
ans1++;
ans1 += cnt1;
ans2 += cnt0;
last=i;
}
}
cnt0 = 0;
cnt1 = 0;
j = 0;
last = -1;
for(int i = 0; i < n; i++) {
if(s[i]=='b'&&last==-1) {
last=i;
ans1++;
continue;
}
if(s[i]=='b'){
j++;
if(i%2!=last%2){
swap(cnt0,cnt1);
}
if((i-last+1)%2==0){
cnt0++;
}
else cnt1++;
last=i;
ans1++;
ans1 += cnt1;
ans2 += cnt0;
}
}
cout << ans2 << " " << ans1;
}