-
Notifications
You must be signed in to change notification settings - Fork 0
/
poj3276.cpp
62 lines (57 loc) · 1.07 KB
/
poj3276.cpp
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
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <set>
#define INF 10000000
using namespace std;
typedef pair<int,int> P;
int n;
int isBack[5000];
int isChanged[5000];
int main(){
cin >> n;
for(int i=0;i<n;i++){
char temp;
cin >> temp;
if(temp=='B'){
isBack[i] = 1;
}else{
isBack[i] = 0;
}
}
int ansK=1,ansM=n;
for(int k=1;k<=n;k++){
fill(isChanged,isChanged+n,0);
bool isFound = true;
int sum=0,res = 0;
for(int i=0;i<n-k+1;i++){
if((isBack[i]+sum)%2!=0){
res++;
isChanged[i] = 1;
}
sum+=isChanged[i];
if(i-k+1>=0){
sum -= isChanged[i-k+1];
}
}
for(int i=n-k+1;i<n;i++){
if((isBack[i]+sum)%2!=0){
isFound = false;
break;
}
if(i-k+1>=0){
sum -= isChanged[i-k+1];
}
}
//cout << "k:" << k << ",res:"<< res << endl;
if(isFound && res<ansM){
ansM = res;
ansK = k;
}
}
cout << ansM << " " << ansK << endl;
}