結果
問題 | No.5005 3-SAT |
ユーザー | terry_u16 |
提出日時 | 2022-04-29 14:37:25 |
言語 | Rust (1.77.0 + proconio) |
結果 |
TLE
|
実行時間 | - |
コード長 | 5,288 bytes |
コンパイル時間 | 939 ms |
実行使用メモリ | 9,072 KB |
スコア | 0 |
最終ジャッジ日時 | 2022-04-29 14:37:33 |
合計ジャッジ時間 | 7,847 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | -- | - |
testcase_02 | -- | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
testcase_54 | -- | - |
testcase_55 | -- | - |
testcase_56 | -- | - |
testcase_57 | -- | - |
testcase_58 | -- | - |
testcase_59 | -- | - |
testcase_60 | -- | - |
testcase_61 | -- | - |
testcase_62 | -- | - |
testcase_63 | -- | - |
testcase_64 | -- | - |
testcase_65 | -- | - |
testcase_66 | -- | - |
testcase_67 | -- | - |
testcase_68 | -- | - |
testcase_69 | -- | - |
testcase_70 | -- | - |
testcase_71 | -- | - |
testcase_72 | -- | - |
testcase_73 | -- | - |
testcase_74 | -- | - |
testcase_75 | -- | - |
testcase_76 | -- | - |
testcase_77 | -- | - |
testcase_78 | -- | - |
testcase_79 | -- | - |
testcase_80 | -- | - |
testcase_81 | -- | - |
testcase_82 | -- | - |
testcase_83 | -- | - |
testcase_84 | -- | - |
testcase_85 | -- | - |
testcase_86 | -- | - |
testcase_87 | -- | - |
testcase_88 | -- | - |
testcase_89 | -- | - |
testcase_90 | -- | - |
testcase_91 | -- | - |
testcase_92 | -- | - |
testcase_93 | -- | - |
testcase_94 | -- | - |
testcase_95 | -- | - |
testcase_96 | -- | - |
testcase_97 | -- | - |
testcase_98 | -- | - |
testcase_99 | -- | - |
ソースコード
use std::time::Instant; macro_rules! get { ($t:ty) => { { let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); line.trim().parse::<$t>().unwrap() } }; ($($t:ty),*) => { { let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); let mut iter = line.split_whitespace(); ( $(iter.next().unwrap().parse::<$t>().unwrap(),)* ) } }; ($t:ty; $n:expr) => { (0..$n).map(|_| get!($t) ).collect::<Vec<_>>() }; ($($t:ty),*; $n:expr) => { (0..$n).map(|_| get!($($t),*) ).collect::<Vec<_>>() }; ($t:ty ;;) => { { let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|t| t.parse::<$t>().unwrap()) .collect::<Vec<_>>() } }; ($t:ty ;; $n:expr) => { (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>() }; } #[allow(unused_macros)] macro_rules! chmin { ($base:expr, $($cmps:expr),+ $(,)*) => {{ let cmp_min = min!($($cmps),+); if $base > cmp_min { $base = cmp_min; true } else { false } }}; } #[allow(unused_macros)] macro_rules! chmax { ($base:expr, $($cmps:expr),+ $(,)*) => {{ let cmp_max = max!($($cmps),+); if $base < cmp_max { $base = cmp_max; true } else { false } }}; } #[allow(unused_macros)] macro_rules! min { ($a:expr $(,)*) => {{ $a }}; ($a:expr, $b:expr $(,)*) => {{ std::cmp::min($a, $b) }}; ($a:expr, $($rest:expr),+ $(,)*) => {{ std::cmp::min($a, min!($($rest),+)) }}; } #[allow(unused_macros)] macro_rules! max { ($a:expr $(,)*) => {{ $a }}; ($a:expr, $b:expr $(,)*) => {{ std::cmp::max($a, $b) }}; ($a:expr, $($rest:expr),+ $(,)*) => {{ std::cmp::max($a, max!($($rest),+)) }}; } #[allow(unused_macros)] macro_rules! mat { ($e:expr; $d:expr) => { vec![$e; $d] }; ($e:expr; $d:expr $(; $ds:expr)+) => { vec![mat![$e $(; $ds)*]; $d] }; } #[derive(Debug, Clone, Copy)] struct Requirement { digit: usize, value: usize, } #[derive(Debug, Clone)] struct Choice { requirements: [Requirement; 3], } #[derive(Debug, Clone)] struct Input { since: Instant, choices: Vec<Choice>, } const CHOICES_COUNT: usize = 2048; const DIGIT_LEN: usize = 256; const TIME_LIMIT: f64 = 1.95; fn main() { let input = read_input(); let solution = solve(&input); write_output(&solution); } fn read_input() -> Input { let mut choices = vec![]; for _ in 0..CHOICES_COUNT { let (a, b, c, p, q, r) = get!(usize, usize, usize, usize, usize, usize); let requirements = [ Requirement { digit: a, value: p }, Requirement { digit: b, value: q }, Requirement { digit: c, value: r }, ]; let choice = Choice { requirements }; choices.push(choice); } let since = Instant::now(); let input = Input { since, choices }; input } fn solve(input: &Input) -> Vec<usize> { let mut counts = vec![0; DIGIT_LEN]; let mut solution = vec![0; DIGIT_LEN]; let mut best_solution = vec![0; DIGIT_LEN]; let mut best_score = 0; let mut total_count = 0; dfs( input, &mut solution, &mut best_solution, &mut best_score, &mut counts, &mut total_count, 0, ); eprintln!("score: {}", best_score); best_solution } fn dfs( input: &Input, solution: &mut Vec<usize>, best_solution: &mut Vec<usize>, best_score: &mut usize, counts: &mut [usize], total_count: &mut usize, depth: usize, ) -> bool { if *total_count % 1000 == 0 { let elapsed = (Instant::now() - input.since).as_secs_f64(); if elapsed > TIME_LIMIT { return false; } } if chmax!(*best_score, depth) { *best_solution = solution.clone(); } if depth == CHOICES_COUNT { return false; } for req in input.choices[depth].requirements.iter() { if counts[req.digit] == 0 || solution[req.digit] == req.value { counts[req.digit] += 1; *total_count += 1; solution[req.digit] = req.value; let over = dfs( input, solution, best_solution, best_score, counts, total_count, depth + 1, ); if over { return false; } counts[req.digit] -= 1; } } return true; } fn write_output(solution: &[usize]) { let mut result = String::new(); for v in solution.iter().rev() { if *v == 0 { result.push('0'); } else { result.push('1'); } } println!("{}", result); }