結果

問題 No.1369 交換門松列・竹
ユーザー akakimidoriakakimidori
提出日時 2021-01-29 21:43:18
言語 Rust
(1.77.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 2,583 bytes
コンパイル時間 1,883 ms
コンパイル使用メモリ 145,948 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-09 15:04:25
合計ジャッジ時間 3,009 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 0 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 9 ms
4,376 KB
testcase_15 AC 13 ms
4,380 KB
testcase_16 AC 28 ms
4,380 KB
testcase_17 AC 27 ms
4,376 KB
testcase_18 AC 27 ms
4,376 KB
testcase_19 AC 13 ms
4,376 KB
testcase_20 AC 44 ms
4,376 KB
testcase_21 AC 12 ms
4,380 KB
testcase_22 AC 44 ms
4,376 KB
testcase_23 AC 26 ms
4,376 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 18 ms
4,376 KB
testcase_26 AC 20 ms
4,380 KB
testcase_27 AC 23 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 3 ms
4,380 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 AC 6 ms
4,380 KB
testcase_33 AC 41 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// ---------- begin scannner ----------
#[allow(dead_code)]
mod scanner {
    use std::str::FromStr;
    pub struct Scanner<'a> {
        it: std::str::SplitWhitespace<'a>,
    }
    impl<'a> Scanner<'a> {
        pub fn new(s: &'a String) -> Scanner<'a> {
            Scanner {
                it: s.split_whitespace(),
            }
        }
        pub fn next<T: FromStr>(&mut self) -> T {
            self.it.next().unwrap().parse::<T>().ok().unwrap()
        }
        pub fn next_bytes(&mut self) -> Vec<u8> {
            self.it.next().unwrap().bytes().collect()
        }
        pub fn next_chars(&mut self) -> Vec<char> {
            self.it.next().unwrap().chars().collect()
        }
        pub fn next_vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
            (0..len).map(|_| self.next()).collect()
        }
    }
}
// ---------- end scannner ----------

use std::io::Write;

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut sc = scanner::Scanner::new(&s);
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    run(&mut sc, &mut out);
}

fn kadomatsu(a: &[u32]) -> bool {
    a[0] != a[1] && a[1] != a[2] && a[2] != a[0] && (a[1] > a[0].max(a[2]) || a[1] < a[0].min(a[2]))
}

fn run<W: Write>(sc: &mut scanner::Scanner, out: &mut std::io::BufWriter<W>) {
    let t: usize = sc.next();
    for _ in 0..t {
        let n: usize = sc.next();
        let mut a: Vec<u32> = sc.next_vec(n);
        let x = (0..=(n - 3))
            .filter(|&x| !kadomatsu(&a[x..(x + 3)]))
            .collect::<Vec<_>>();
        if x.len() > 6 {
            writeln!(out, "No").ok();
            continue;
        }
        let mut ans = "No";
        for &y in x.iter() {
            for p in y..n.min(y + 3) {
                for i in 0..n {
                    if i == p {
                        continue;
                    }
                    a.swap(i, p);
                    let mut ok = true;
                    for &j in [i - 2, i - 1, i, p - 2, p - 1, p].iter() {
                        if j <= n - 3 {
                            ok &= kadomatsu(&a[j..(j + 3)]);
                        }
                    }
                    for &x in x.iter() {
                        ok &= kadomatsu(&a[x..(x + 3)]);
                    }
                    if ok {
                        ans = "Yes";
                    }
                    a.swap(i, p);
                }
            }
        }
        writeln!(out, "{}", ans).ok();
    }
}
0