結果

問題 No.2692 How Many Times Reached?
ユーザー well-defined
提出日時 2024-09-17 09:49:28
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,180 bytes
コンパイル時間 15,188 ms
コンパイル使用メモリ 404,600 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-17 09:49:48
合計ジャッジ時間 16,855 ms
ジャッジサーバーID
(参考情報)
judge4 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

use proconio::input;
use proconio::marker::Chars;

fn main () {
    input! {
        n: usize,
        b: [Chars;n],
    }
    //println!("{:?}",b);
    let mut ans = 0;

    let b = b.iter()
        .map(|row| {
            row.iter()
                .map(|&c| {
                    match c {
                        'A' => 1,
                        'B' => -1,
                        _ => 0,
                    }
                })
                .collect::<Vec<i32>>()
        })
        .collect::<Vec<Vec<i32>>>();

    ans += b.iter()
        .filter(|&row| {
            row.iter()
                .fold(0, |sum, &x| {
                    sum + x
                }) == (n-1) as i32
        })
        .count();

    ans += (0..n)
        .filter(|&col| {
            b.iter()
                .fold(0, |sum, row| {
                    sum + row[col]
                }) == (n-1) as i32
        })
        .count();
    
    let mut tmp = 0;
    for i in 0..n {
        tmp += b[i][i];
    }
    if tmp == (n-1) as i32 {ans += 1;}
    tmp = 0;
    for i in 0..n {
        tmp += b[n-1-i][i];
    }
    if tmp == (n-1) as i32 {ans += 1;}

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