-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeforces Round 159 (Div. 2) - B. Playing Cubes.cpp
More file actions
116 lines (101 loc) · 2.41 KB
/
Codeforces Round 159 (Div. 2) - B. Playing Cubes.cpp
File metadata and controls
116 lines (101 loc) · 2.41 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
107
108
109
110
111
112
113
114
115
// std::setvbuf(stdout, nullptr, _IOFBF, BUFSIZ); //(will neglect the c's stdio.h property of doing inline flushing with every line of code)
//std::ios_base::sync_with_stdio(false); // (removes the interoperability that happens between C's stdio.h and iostream )
#include <iostream>
//#include<numeric>
//#include<vector>
#include<cmath>
//#include<stack>
//#include <iomanip>
//#include <vector>
#include<bits/stdc++.h>
//#include <bitset>
////#include<iomanip>
//#include <algorithm>
//#include<queue>
////#include<deque>
////#include<numeric>
//#include<set>
//#include<unordered_set>
//#include<map>
////#include<fstream>
//#include<sstream>
////#include <thread>
////#include <chrono>
//#include<cstring>
//#include<string>
//#include <unordered_map>
////#include <thread>
////#include<limits>+++
using namespace std;
//Stupid problem!
string func(int n,int m, string start){
bool vasya =true;
int extend = n+m;
for(int i = 0;i<extend ;++i){
if(vasya){
if((start[i] == 'r') && m){
start+='b';
--m;
}
else if((start[i] == 'b') && n){
start+='r';
--n;
}
else if (!m){
start+='r';
--n;
}
else{
start+='b';
--m;
}
}
else{
if((start[i] == 'r') && n){
start+='r';
--n;
}
else if((start[i] == 'b') && m){
start+='b';
--m;
}
else if (!m){
start+='r';
--n;
}
else{
start+='b';
--m;
}
}
vasya =!vasya;
}
return start;
}
pair<int,int> counter(string s){
char prev = s[0];
int fir=0,sec=0;
for(int i=1;i<s.size();++i){
if(s[i]==prev) fir++;
else sec++;
prev = s[i];
}
return {fir,sec};
}
int main(){
int n,m;
cin>>n>>m;
pair<int,int> f = counter(func(n,m-1,"b"));
pair<int,int> s = counter(func(n-1,m,"r"));
if(s.first>f.first){
cout<<s.first<<" "<<s.second;
}
else if(s.first<f.first){
cout<<f.first<<" "<<f.second;
}
else{
if(s.second< f.second)
cout<<s.first<<" "<<s.second;
else cout<<f.first<<" "<<f.second;
}
}