File tree Expand file tree Collapse file tree 1 file changed +75
-0
lines changed Expand file tree Collapse file tree 1 file changed +75
-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:: cmp:: Ordering ;
5+ use std:: cmp:: Reverse ;
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: Chars
17+ }
18+
19+ let limit = 1 << n;
20+ let mut memo = vec ! [ false ; limit] ;
21+
22+ if s[ limit-2 ] == '1' {
23+ println ! ( "No" ) ;
24+ continue
25+ }
26+
27+ for x in 0 ..limit-1 {
28+ if s[ x] == '1' {
29+ memo[ x+1 ] = true ;
30+ }
31+ }
32+
33+ let mut success = false ;
34+ let mut i = 0 ;
35+ while !success && i < n {
36+
37+ let si = 1 << i;
38+ if memo[ si] {
39+ i += 1 ;
40+ continue ;
41+ }
42+
43+ memo[ si] = true ;
44+ let mut stack = vec ! [ si] ;
45+
46+ while !stack. is_empty ( ) {
47+ let mut new_stack = vec ! [ ] ;
48+ for j in stack {
49+ for x in 0 ..n {
50+ if j >> x & 1 == 0 {
51+ let next = j | ( 1 << x) ;
52+ if !memo[ next] {
53+ memo[ next] = true ;
54+ new_stack. push ( next) ;
55+ }
56+ }
57+ }
58+ }
59+ stack = new_stack;
60+ }
61+ if memo[ limit - 1 ] {
62+ success = true ;
63+ break
64+ } else {
65+ i += 1 ;
66+ }
67+ }
68+
69+ if success {
70+ println ! ( "Yes" ) ;
71+ } else {
72+ println ! ( "No" ) ;
73+ }
74+ }
75+ }
You can’t perform that action at this time.
0 commit comments