File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ /** THIS IS AN OUTPUT FILE. NOT EDIT THIS FILE DIRECTLY. **/
2
+ use proconio:: input;
3
+ use proconio:: marker:: * ;
4
+ use std:: marker:: PhantomData ;
5
+ use std:: cmp:: * ;
6
+ use std:: collections:: * ;
7
+
8
+ fn main ( ) {
9
+ input ! {
10
+ t: usize ,
11
+ }
12
+
13
+ for _ in 0 ..t {
14
+ input ! {
15
+ n: usize ,
16
+ s: String ,
17
+ }
18
+
19
+ let mut a = vec ! [ 0i64 ; n+1 ] ;
20
+ let mut b = vec ! [ 0i64 ; n+1 ] ;
21
+ let mut c = vec ! [ 0i64 ; n+1 ] ;
22
+
23
+ for i in 0 ..n {
24
+ let one = & s[ i..i+1 ] == "1" ;
25
+ a[ i+1 ] = a[ i] ;
26
+ b[ i+1 ] = b[ i] ;
27
+ if one {
28
+ b[ i+1 ] += 1 ;
29
+ } else {
30
+ a[ i+1 ] += 1 ;
31
+ }
32
+ c[ i+1 ] = a[ i+1 ] - b[ i+1 ] ;
33
+ }
34
+
35
+ let mut result = 1i64 << 60 ;
36
+ let mut temp = -1i64 << 60 ;
37
+ for i in 0 ..n+1 {
38
+ temp = std:: cmp:: max ( temp, c[ i] ) ;
39
+ result = std:: cmp:: min ( result, c[ i] -temp) ;
40
+ }
41
+
42
+ println ! ( "{}" , result+b[ n] ) ;
43
+ }
44
+ }
You can’t perform that action at this time.
0 commit comments