ä»åã®ABCã¯æãããåã ã£ãã å解æ³ãéããªã©å¹¸éãããé»ããã©ã ã£ãããã³ã³ãã£ã·ã§ã³ã«ãã£ã¦ã¯ç·ããããåºã¦ããããããªãæãã ã
ããããã御èªãä½éããåã¨ãããã¨ã§ããªãããã®ã¡ãã»ã¼ã¸ãåºãã¦ããããããªãããªã¨ã¯æã£ã¦ãããã
ãBã«ã¯ã³ã¼ãã¼ã±ã¼ã¹ã¯ãªãã ãããã¨æã£ãããH == 1ã§è§ãã¾ã£ããåããªããã ãCãããã¯å ¨æ¢ç´¢ãããããããªããã©ãEã¾ã§æ¥ããDPã¨ãæååãªããã¼ãªã³ã°ããã·ã¥ãã¨æã£ã¦ãããEãå ¨æ¢ç´¢ãã ã¨ã¾ãããã¤ãã®ABCããéå¦ç¿ãã¦ãã¾ã£ãåéã«æèã®å¤ããZã¬ã³ãç´æããã¦ããæãã®ã³ã³ãã¹ãã§ãã£ãã
æ¬å®¶è§£èª¬ãä¸å¯§ãªã®ã§ãããã°ã¯ãã£ããç®ã§ã
æ¬çªã§ã®æ¹é
a->b->cãb->a->cã®permutaionããã¹ã¦èª¿ã¹ããã«ãããã«ã¤ãã¦ãa->bã®ãããå¹ ã¨b->cã®ãããå¹ ã調ã¹ãã æç´ã«ããã¨éã«åããªããããã§ã貪欲ã«a->bã®ãã£ã¨ãçããããå¹ ã®ã¿ã調ã¹ãã¨ãå ¨ä½ãæçã«ãªãåãè¦éããã¨ãããã®ã¯å ¬å¼ã®è§£èª¬ã®éãã
åè¨ç®ã«ãã£ã¦ãªã¼ãã¼ãè½ã¨ãã®ãæ³å®è§£ã ã£ãããã ã
ããããèªåã§ã¯å ¨ãæãæµ®ãã°ãè¨ç®éã®åæ¸ã«è¦æ¦ã
ããã§ã貪欲æ³ãå°ãæ¹è¯ãããa->bã®ãã¹ã10ã®çããããããããå¹ ã«å¯¾ãb->cã®æçã®ãããå¹ ãæ¢ããã¨ãã貪欲æ³ãå°ãã ããã·ã«ãããããªç²¾åº¦æ¹åãæãã¤ãã
ãããã«æåºãã¦ã¿ãã¨ã
1ã±ã¼ã¹ã®ã¿è½ã¡ã¦ãã
ããããããããã¡ãã£ã¨é å¼µãã°ãããããããªãï¼ãã¨æããã¹ã10->ãã¹ã50ã«ãã¦æãè¾¼ãã
Submission #10878091 - Panasonic Programming Contest 2020
éã£ãããããã¦ãé«åº¦å解æ³äººæã¨ãã¦é»ããã©ç²å¾ã«æåãã¾ããããã§ããã
æ£ããæ¹é
æ¦ãå ¬å¼ã®éãã®æ¹éã§ãã https://img.atcoder.jp/panasonic2020/editorial.pdf
fn is_ok(a: &Vec<char>, b: &Vec<char>) -> Vec<bool> { let mut ret = vec![true; a.len()]; for i in 0..a.len() { if (0..b.len()) .any(|j| i + j < a.len() && b[j] != '?' && a[i + j] != '?' && b[j] != a[i + j]) { ret[i] = false; } } ret } fn main() { let a = read::<String>().chars().collect::<Vec<_>>(); let b = read::<String>().chars().collect::<Vec<_>>(); let c = read::<String>().chars().collect::<Vec<_>>(); // ï¼ã¤ã®æååãiããããã¨ãã«çç¾ããªããã©ããã // [0]a->b, [1]b->a, [2]b->c, [3]c->b, [4]a->c, [5]c->aã®é¢ä¿ã表ãã let mut ok = vec![vec![]; 6]; for (i, &(ref a, ref b)) in [(&a, &b), (&b, &a), (&b, &c), (&c, &b), (&a, &c), (&c, &a)] .iter() .enumerate() { ok[i] = is_ok(&a, &b); } let mut ans = a.len() + b.len() + c.len(); let criterion = |ok: &Vec<bool>, i| i >= ok.len() || ok[i]; for &(ref ok0, ref ok1, ref ok2, l1, l2, l3) in &[ (&ok[0], &ok[2], &ok[4], a.len(), b.len(), c.len()), // a -> b -> c (&ok[4], &ok[3], &ok[0], a.len(), c.len(), b.len()), // a -> c -> b (&ok[1], &ok[4], &ok[2], b.len(), a.len(), c.len()), // b -> a -> c (&ok[2], &ok[5], &ok[1], b.len(), c.len(), a.len()), // b -> c -> a (&ok[5], &ok[0], &ok[3], c.len(), a.len(), b.len()), // c -> a -> b (&ok[3], &ok[1], &ok[5], c.len(), b.len(), a.len()), // c -> b -> a ] { for i in 0..ok0.len() { if !criterion(ok0, i) { continue; } // a->bã®ãããå¹ ãiãb->cã®ãããå¹ ãj-iãããããã¨a->bã¯jããã¦ãããi, jã¯éè² let j = (i..ok0.len() + ok1.len()) .find(|&j| criterion(ok1, j - i) && criterion(ok2, j)) .unwrap(); let cur_length = *[l1, i + l2, j + l3].iter().max().unwrap(); ans = std::cmp::min(ans, cur_length); } } println!("{}", ans); } fn read<T: std::str::FromStr>() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() }
a, b, cãããã§ããããã«ãªã£ã¦ãã¾ã£ãforæãã¤ãããããã ãæ°ãã¤ããã°ãªãã¨ããªãã
permutation
ã¨ã使ãã°ãã£ã¨è³¢ãæ¸ãæ¹ãã§ãããããããªãããããã£ã¦ãã°ããããªã®ã§ãããã
ã¨ããã§ãæè¿ã¯for
ã¨ãif
ã使ããããªãã¹ããany()
ã¨ãall()
ã¨ãfind()
ã使ãããã«ãã¦ããã
ãããã使ã£ãã»ãããã°ãã¥ãããèªã¿ãããã
ãã ããis_ok
ã¯collectã使ãã°æ®ã£ã¦ããforæãæ¶ããã¨ãã§ããããããã¾ã§ããã¨éã«ãããã¥ãããªãã®ã§ããã®è¾ºãèªåã«ã¨ã£ã¦ã¯ä¸çªããããããè½ã¨ãæã