|
|
@ -11,27 +11,40 @@ use input::INPUT;
|
|
|
|
#[cfg(not(feature="big"))] const TARGET: u64 = 2020;
|
|
|
|
#[cfg(not(feature="big"))] const TARGET: u64 = 2020;
|
|
|
|
#[cfg(feature="big")] const TARGET: u64 = 99920044;
|
|
|
|
#[cfg(feature="big")] const TARGET: u64 = 99920044;
|
|
|
|
|
|
|
|
|
|
|
|
// O(n^2)
|
|
|
|
// O(n^2) ?
|
|
|
|
fn main() {
|
|
|
|
fn main() {
|
|
|
|
let deficits: HashMap<u64, usize> = (0..)
|
|
|
|
// doesn't work on big input?
|
|
|
|
.zip(INPUT.iter().copied())
|
|
|
|
#[cfg(feature="u128")]
|
|
|
|
.filter_map(|(i, x)| TARGET.checked_sub(x).map(|x| (x, i)))
|
|
|
|
let input: Box<[_]> = INPUT[..].iter().map(|&x| x as u128).collect();
|
|
|
|
|
|
|
|
#[cfg(feature="u128")]
|
|
|
|
|
|
|
|
let target = TARGET as u128;
|
|
|
|
|
|
|
|
// ^ doesn't help..
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(not(feature="u128"))]
|
|
|
|
|
|
|
|
let input = &INPUT[..];
|
|
|
|
|
|
|
|
#[cfg(not(feature="u128"))]
|
|
|
|
|
|
|
|
let target = TARGET;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let deficits: HashMap<_, usize> = (0..)
|
|
|
|
|
|
|
|
.zip(input.iter().copied())
|
|
|
|
|
|
|
|
.filter_map(|(i, x)| target.checked_sub(x).map(|x| (x, i)))
|
|
|
|
.collect();
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
|
|
|
|
//eprintln!("calculated deficits: {}", deficits.len());
|
|
|
|
eprintln!("calculated deficits: {}", deficits.len());
|
|
|
|
for (i, ix) in (0..).zip(INPUT.iter().copied())
|
|
|
|
for (i, ix) in (0..).zip(input.iter().copied())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for jx in INPUT[i..].iter().copied().skip(1)
|
|
|
|
for jx in input[i..].iter().copied().skip(1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let sum = ix+jx;
|
|
|
|
if let Some(sum) = ix.checked_add(jx) {
|
|
|
|
if let Some(&idx) = deficits.get(&sum)
|
|
|
|
if let Some(&idx) = deficits.get(&sum)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//eprintln!("solution found?");
|
|
|
|
eprintln!("solution found?");
|
|
|
|
println!("{}", if let Some(x) = INPUT[idx].checked_mul(ix).map(|x| x.checked_mul(jx)).flatten()
|
|
|
|
println!("{}", if let Some(x) = input[idx].checked_mul(ix).map(|x| x.checked_mul(jx)).flatten()
|
|
|
|
{ x } else { continue; });
|
|
|
|
{ x } else { continue; });
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//panic!("no solution");
|
|
|
|
panic!("no solution");
|
|
|
|
}
|
|
|
|
}
|
|
|
|