-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRNG Runelength.java
More file actions
53 lines (53 loc) · 1.39 KB
/
RNG Runelength.java
File metadata and controls
53 lines (53 loc) · 1.39 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
import java.util.*;
public class Eccpr{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
String s=sc.next();
ArrayList<Integer>out=new ArrayList<>();
int cnt=0,max=0;
for(int i=0;i<s.length();i++){
if(s.charAt(i)=='0'){
if(cnt>max){
max=cnt;
}
cnt=0;
}else{
cnt++;
}
}
if(cnt>max){
max=cnt;
}
for(int i=0;i<max;i++){
out.add(0);
}
cnt=0;
for(int i=0;i<s.length();i++){
if(s.charAt(i)=='0'){
if(cnt!=0){
n=out.get(cnt-1)+1;
out.set(cnt-1,n);
}
cnt=0;
}else{
cnt++;
}
}
if(cnt!=0){
n=out.get(cnt-1)+1;
out.set(cnt-1,n);
}
max=1;
System.out.print(out.get(0)+" ");
cnt=out.get(0);
for(int i=1;i<out.size();i++){
System.out.print(out.get(i)+" ");
if(out.get(i)>cnt){
max=0;
}else cnt=out.get(i);
}
System.out.println();
System.out.println(max);
}
}