結果

問題 No.3110 Like CPCTF?
ユーザー zer0-star
提出日時 2025-04-19 00:37:19
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,253 bytes
コンパイル時間 13,239 ms
コンパイル使用メモリ 385,172 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-04-19 00:37:33
合計ジャッジ時間 14,183 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: constant `DIRS` is never used
 --> src/main.rs:5:7
  |
5 | const DIRS: [(isize, isize); 4] = [(0, 1), (1, 0), (0, -1), (-1, 0)];
  |       ^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: trait `OrdExt` is never used
 --> src/main.rs:7:7
  |
7 | trait OrdExt {
  |       ^^^^^^

ソースコード

diff #

use std::collections::BTreeSet;

use proconio::{fastout, input, marker::Chars};

const DIRS: [(isize, isize); 4] = [(0, 1), (1, 0), (0, -1), (-1, 0)];

trait OrdExt {
    fn chmax(&mut self, other: Self) -> bool;
    fn chmin(&mut self, other: Self) -> bool;
}

impl<T: Ord> OrdExt for T {
    fn chmax(&mut self, other: Self) -> bool {
        if *self < other {
            *self = other;
            true
        } else {
            false
        }
    }

    fn chmin(&mut self, other: Self) -> bool {
        if *self > other {
            *self = other;
            true
        } else {
            false
        }
    }
}

#[fastout]
fn main() {
    input! {
        n: usize,
        s: Chars
    }

    let mut ans = 0;

    for a in 0..n {
        for b in a + 1..n {
            for c in b + 1..n {
                for d in c + 1..n {
                    for e in d + 1..n {
                        let t = [s[a], s[b], s[c], s[d], s[e]];
                        if is_cpctf_like(t) {
                            ans += 1;
                        }
                    }
                }
            }
        }
    }

    println!("{}", ans);
}

fn is_cpctf_like(s: [char; 5]) -> bool {
    s[0] == s[2] && BTreeSet::from(s).len() == 4
}
0