Код: Выделить всё
import java.util.Scanner;
public class Main {
static int count = 0;
static int ans = Integer.MAX_VALUE;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
sc.nextLine();
String s = sc.nextLine();
char[] str = new char[N];
str[0] = s.charAt(0);
char pre = str[0];
for(int i = 1;i < N;i++){
str[i] = s.charAt(i);
count += str[i] == pre ? 1 : 0;
pre = pre == '0' ? '1' : '0';
}
if(count == 0) {
System.out.println(0);
return;
}
f(str,0,0,'1');
f(str,0,0,'0');
System.out.println(Math.min(ans,count));
}
public static void f(char[] str,int index,int cur,char pre){
if(ans
Подробнее здесь: [url]https://stackoverflow.com/questions/78361180/online-judge-oj-cannot-pass-but-the-local-test-cases-are-correct[/url]