File tree 1 file changed +39
-0
lines changed
1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ using namespace std ;
3
+
4
+
5
+ #define char2int (x ) ((x) - ' 0' )
6
+
7
+ int main (){
8
+ ios :: sync_with_stdio (0 );
9
+ cin.tie (0 );
10
+ // cout.tie(0);
11
+ std::cout.precision (10 );
12
+ std::cout.setf ( std::ios::fixed, std:: ios::floatfield );
13
+
14
+ int T;
15
+ cin >> T;
16
+ for (int tt =1 ; tt <=T ; ++tt)
17
+ {
18
+ cout << " Case #" << tt << " : " ;
19
+ int n;
20
+ cin >> n;
21
+ string s;
22
+ cin >> s;
23
+ vector<int > val (s.size ()),sum (s.size ()+1 );
24
+ transform (s.begin (),s.end (),val.begin (),[](char e){return char2int (e);});
25
+ // const auto & print = for_each(val.begin(),val.end(),[](const int &e){cout << e << "\n";});
26
+ partial_sum (val.begin (),val.end (),sum.begin ()+1 );
27
+ sum[0 ] =0 ;
28
+ // for_each(sum.begin(),sum.end(),print);
29
+ int ans =0 ;
30
+ for (int i= 0 ; i<= n/2 ; ++i)
31
+ {
32
+ ans = max (ans,sum[i+(n+1 )/2 ] - sum[i]);
33
+ }
34
+ cout << ans <<" \n " ;
35
+ }
36
+
37
+
38
+ return 0 ;
39
+ }
You can’t perform that action at this time.
0 commit comments