結果

問題 No.1707 Simple Range Reverse Problem
コンテスト
ユーザー phspls
提出日時 2022-10-17 02:28:25
言語 Rust
(1.94.0 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
WA  
実行時間 -
コード長 1,400 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,863 ms
コンパイル使用メモリ 190,464 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-03-15 21:23:51
合計ジャッジ時間 2,423 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 6 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

use std::collections::VecDeque;


fn solve() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let mut a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let mut not_checked = (1..=n).collect::<VecDeque<usize>>();
    while not_checked.len() > 1 {
        let front = not_checked[0];
        let back = not_checked[not_checked.len()-1];
        if a[front-1] != front || a[back+n-1] != back {
            break;
        }
        if a[front+n-1] == a[front-1] && a[back-1] == a[back+n-1] {
            not_checked.pop_back();
            not_checked.pop_front();
        } else if a[front+n-1] != a[front-1] && a[back-1] != a[back+n-1] {
            break;
        } else if a[front+n-1] != a[front-1] {
            a[back-1..=back+n-1].reverse();
            not_checked.pop_back();
        } else {
            a[front-1..=front+n-1].reverse();
            not_checked.pop_front();
        }
    }
    if (0..2*n).filter(|&i| (i%n)+1 != a[i]).count() == 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let mut t = String::new();
    std::io::stdin().read_line(&mut t).ok();
    let t: usize = t.trim().parse().unwrap();
    for _ in 0..t {
        solve();
    }
}
0