Submission #1989865
Source Code Expand
// use std::ops::{Index, IndexMut}; // use std::cmp::{Ordering, min, max}; // use std::collections::{BinaryHeap, BTreeMap}; // use std::collections::btree_map::Entry::{Occupied, Vacant}; // use std::clone::Clone; fn getline() -> String{ let mut res = String::new(); std::io::stdin().read_line(&mut res).ok(); res } macro_rules! readl { ($t: ty) => { { let s = getline(); s.trim().parse::<$t>().unwrap() } }; ($( $t: ty),+ ) => { { let s = getline(); let mut iter = s.trim().split(' '); ($(iter.next().unwrap().parse::<$t>().unwrap(),)*) } }; } macro_rules! readlvec { ($t: ty) => { { let s = getline(); let iter = s.trim().split(' '); iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>() } } } macro_rules! mvec { ($v: expr, $s: expr) => { vec![$v; $s] }; ($v: expr, $s: expr, $($t: expr),*) => { vec![mvec!($v, $($t),*); $s] }; } macro_rules! debug { ($x: expr) => { println!("{}: {:?}", stringify!($x), $x) } } fn printiter<'a, T>(v: &'a T) where &'a T: std::iter::IntoIterator, <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display { for (i,e) in v.into_iter().enumerate() { if i != 0 { print!(" "); } print!("{}", e); } println!(""); } fn naive(a: usize, b: usize) -> u64 { println!("{:b}", a); println!("{:b}", b); let up = |mut x: usize| { let mut res = 0; while x != 0 { res += 1; x >>= 1; } res }; let mut dp = vec![false; 1<<up(b)]; dp[a] = true; // debug!(dp); for num in a+1..b+1 { // debug!(num); let mut nex = dp.clone(); nex[num] = true; for mask in 0..dp.len() { nex[mask|num] = nex[mask|num]||dp[mask]; } dp = nex; } let a = dp.iter().fold(0, |sum, &x| { if x { sum + 1 } else { sum } }); // debug!(dp); a } fn solve(mut a: usize, mut b: usize) -> u64 { const MAX: usize = 61; for i in (0..MAX).rev() { if ((a>>i)&1) == ((b>>i)&1) { a = (!(1<<i))&a; b = (!(1<<i))&b; } else { break; } } if a == b { return 1; } let blen = { let mut b = b; let mut cnt = 0; while b != 0 { cnt += 1; b >>= 1; } cnt-1 }; // debug!(a); debug!(b); let mut res = ((1<<blen)-a)*2; // debug!((1<<blen)-a); let to = { let mut s = false; let mut res = None; for i in (0..MAX).rev() { if (b>>i)&1 == 1 { // debug!(i); if !s { s = true; } else { res = Some(i); break; } } } res }; // debug!(to); if let Some(to) = to { let add = (1<<to+1); // debug!(add); res += add; res -= std::cmp::max(0, (add as i64 - 1 - a as i64 + 1)) as usize; if a == 0 { } } // res += 1; res as u64 } fn main() { let a = readl!(usize); let b = readl!(usize); // println!("{}", naive(a, b)); println!("{}", solve(a, b)); }
Submission Info
Submission Time | |
---|---|
Task | D - A or...or B Problem |
User | sntea |
Language | Rust (1.15.1) |
Score | 0 |
Code Size | 3620 Byte |
Status | WA |
Exec Time | 2 ms |
Memory | 4352 KB |
Compile Error
warning: unnecessary parentheses around assigned value, #[warn(unused_parens)] on by default --> ./Main.rs:144:19 | 144 | let add = (1<<to+1); | ^^^^^^^^^ warning: function is never used: `printiter`, #[warn(dead_code)] on by default --> ./Main.rs:54:1 | 54 | fn printiter<'a, T>(v: &'a T) | ^ warning: function is never used: `naive`, #[warn(dead_code)] on by default --> ./Main.rs:67:1 | 67 | fn naive(a: usize, b: usize) -> u64 { | ^
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 900 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt, s3.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt, 53.txt, 54.txt, 55.txt, 56.txt, s1.txt, s2.txt, s3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 2 ms | 4352 KB |
02.txt | AC | 2 ms | 4352 KB |
03.txt | AC | 2 ms | 4352 KB |
04.txt | AC | 2 ms | 4352 KB |
05.txt | AC | 2 ms | 4352 KB |
06.txt | AC | 2 ms | 4352 KB |
07.txt | AC | 2 ms | 4352 KB |
08.txt | AC | 2 ms | 4352 KB |
09.txt | AC | 2 ms | 4352 KB |
10.txt | AC | 2 ms | 4352 KB |
11.txt | AC | 2 ms | 4352 KB |
12.txt | AC | 2 ms | 4352 KB |
13.txt | AC | 2 ms | 4352 KB |
14.txt | AC | 2 ms | 4352 KB |
15.txt | WA | 2 ms | 4352 KB |
16.txt | WA | 2 ms | 4352 KB |
17.txt | AC | 2 ms | 4352 KB |
18.txt | WA | 2 ms | 4352 KB |
19.txt | AC | 2 ms | 4352 KB |
20.txt | AC | 2 ms | 4352 KB |
21.txt | AC | 2 ms | 4352 KB |
22.txt | AC | 2 ms | 4352 KB |
23.txt | AC | 2 ms | 4352 KB |
24.txt | AC | 2 ms | 4352 KB |
25.txt | AC | 2 ms | 4352 KB |
26.txt | AC | 2 ms | 4352 KB |
27.txt | AC | 2 ms | 4352 KB |
28.txt | AC | 2 ms | 4352 KB |
29.txt | AC | 2 ms | 4352 KB |
30.txt | AC | 2 ms | 4352 KB |
31.txt | AC | 2 ms | 4352 KB |
32.txt | AC | 2 ms | 4352 KB |
33.txt | AC | 2 ms | 4352 KB |
34.txt | AC | 2 ms | 4352 KB |
35.txt | AC | 2 ms | 4352 KB |
36.txt | AC | 2 ms | 4352 KB |
37.txt | AC | 2 ms | 4352 KB |
38.txt | AC | 2 ms | 4352 KB |
39.txt | AC | 2 ms | 4352 KB |
40.txt | AC | 2 ms | 4352 KB |
41.txt | AC | 2 ms | 4352 KB |
42.txt | AC | 2 ms | 4352 KB |
43.txt | AC | 2 ms | 4352 KB |
44.txt | AC | 2 ms | 4352 KB |
45.txt | AC | 2 ms | 4352 KB |
46.txt | AC | 2 ms | 4352 KB |
47.txt | AC | 2 ms | 4352 KB |
48.txt | AC | 2 ms | 4352 KB |
49.txt | AC | 2 ms | 4352 KB |
50.txt | AC | 2 ms | 4352 KB |
51.txt | AC | 2 ms | 4352 KB |
52.txt | AC | 2 ms | 4352 KB |
53.txt | WA | 2 ms | 4352 KB |
54.txt | AC | 2 ms | 4352 KB |
55.txt | AC | 2 ms | 4352 KB |
56.txt | AC | 2 ms | 4352 KB |
s1.txt | AC | 2 ms | 4352 KB |
s2.txt | AC | 2 ms | 4352 KB |
s3.txt | AC | 2 ms | 4352 KB |