File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ // Time: 405 ms
2+ // Memory: 1300 KB
3+ // Greedy.
4+ // T:O(sum(ni)), S:O(max(ni))
5+ //
6+ import java .util .Scanner ;
7+
8+ public class Codeforces_1988B_Make_Majority {
9+ public static void main (String [] args ) {
10+ Scanner sc = new Scanner (System .in );
11+ int t = sc .nextInt ();
12+ for (int i = 0 ; i < t ; i ++) {
13+ int n = sc .nextInt (), count0 = 0 , count1 = 0 ;
14+ String s = sc .next ();
15+ char prev = ' ' ;
16+ for (int j = 0 ; j < n ; j ++) {
17+ char c = s .charAt (j );
18+ if (prev == ' ' ) {
19+ int k = c == '0' ? count0 ++ : count1 ++;
20+ } else {
21+ if (prev != c ) {
22+ int k = c == '0' ? count0 ++ : count1 ++;
23+ } else if (c == '1' ) {
24+ count1 ++;
25+ }
26+ }
27+ prev = c ;
28+ }
29+
30+ System .out .println (count1 > count0 ? "YES" : "NO" );
31+ }
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments