File tree Expand file tree Collapse file tree 1 file changed +12
-13
lines changed
src/main/java/com/lzw/solutions/codeforces/p2190A Expand file tree Collapse file tree 1 file changed +12
-13
lines changed Original file line number Diff line number Diff line change @@ -26,29 +26,28 @@ void solve() throws IOException {
2626 int n = Integer .parseInt (in .readLine ());
2727 String s = in .readLine ();
2828 assert (s .length () == n );
29- boolean allZeros = true ;
3029 int i ;
31- for (i = 0 ; i < n ; i ++) {
32- if (s .charAt (i ) == '1' ) {
33- allZeros = false ;
34- }
35- }
36- boolean allOnes = true ;
30+ int zero = 0 , one = 0 ;
3731 for (i = 0 ; i < n ; i ++) {
3832 if (s .charAt (i ) == '0' ) {
39- allOnes = false ;
33+ zero ++;
34+ } else {
35+ one ++;
4036 }
4137 }
42- if (allZeros || allOnes ) {
38+ if (zero == n || one == n ) {
4339 out .println ("Bob" );
4440 } else {
4541 out .println ("Alice" );
46- char [] chars = s .toCharArray ();
47- char [] sortedChars = chars .clone ();
48- Arrays .sort (sortedChars );
4942 ArrayList <Integer > positions = new ArrayList <>();
5043 for (i = 0 ; i < n ; i ++) {
51- if (chars [i ] != sortedChars [i ]) {
44+ char target ;
45+ if (i < zero ) {
46+ target = '0' ;
47+ } else {
48+ target = '1' ;
49+ }
50+ if (s .charAt (i ) != target ) {
5251 positions .add (i );
5352 }
5453 }
You can’t perform that action at this time.
0 commit comments