Skip to content

Commit a0b0342

Browse files
committed
add abc415c.rs
1 parent 1466229 commit a0b0342

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

src/abc/abc415c.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
}

0 commit comments

Comments
 (0)