結果

問題 No.488 四角関係
ユーザー mio_hmio_h
提出日時 2017-02-24 22:52:50
言語 Rust
(1.72.1)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 2,874 bytes
コンパイル時間 2,376 ms
コンパイル使用メモリ 163,292 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 23:37:14
合計ジャッジ時間 3,489 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,384 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: use of deprecated associated function `std::error::Error::description`: use the Display impl or to_string()
  --> Main.rs:71:62
   |
71 |             Err(why) => panic!("error in read_line: {}", why.description()),
   |                                                              ^^^^^^^^^^^
   |
   = note: `#[warn(deprecated)]` on by default

warning: 1 warning emitted

ソースコード

diff #

use std::io::{self, Stdin};
use std::str::{self, FromStr};
use std::error::Error;
fn exec() {
    let mut sc = Scanner::new();
    let n: usize = sc.ne();
    let m: usize = sc.ne();
    let mut adj = vec![0; n];
    for _ in 0..m {
        let a: usize = sc.ne();
        let b: usize = sc.ne();
        adj[a] |= 1 << b;
        adj[b] |= 1 << a;
    }
    fn check(a: usize, b: usize) -> bool {
        let c = a & b;
        c.count_ones() == 2
    }
    let mut ans = 0;
    for i in 0..n {
        for j in 0..i {
            for k in 0..j {
                for l in 0..k {
                    let mask = (1 << i) | (1 << j) | (1 << k) | (1 << l);
                    let mut ok = true;
                    ok &= check(adj[i], mask);
                    ok &= check(adj[j], mask);
                    ok &= check(adj[k], mask);
                    ok &= check(adj[l], mask);
                    if ok {
                        ans += 1;
                    }
                }
            }
        }
    }
    println!("{}", ans);
}

fn main() {
    const STACK: usize = 16 * 1024 * 1024;
    let _ = std::thread::Builder::new()
        .stack_size(STACK)
        .spawn(|| { exec(); })
        .unwrap()
        .join()
        .unwrap();
}

#[allow(dead_code)]
struct Scanner {
    stdin: Stdin,
    id: usize,
    buf: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            id: 0,
            buf: Vec::new(),
        }
    }
    fn next_line(&mut self) -> Option<String> {
        let mut res = String::new();
        match self.stdin.read_line(&mut res) {
            Ok(0) => None,
            Ok(_) => Some(res),
            Err(why) => panic!("error in read_line: {}", why.description()),
        }
    }
    fn next<T: FromStr>(&mut self) -> Option<T> {
        while self.buf.len() == 0 {
            self.buf = match self.next_line() {
                Some(r) => {
                    self.id = 0;
                    r.trim().as_bytes().to_owned()
                }
                None => return None,
            };
        }
        let l = self.id;
        assert!(self.buf[l] != b' ');
        let n = self.buf.len();
        let mut r = l;
        while r < n && self.buf[r] != b' ' {
            r += 1;
        }
        let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::<T>() {
            Ok(s) => Some(s),
            Err(_) => {
                panic!("parse error, {:?}",
                       String::from_utf8(self.buf[l..r].to_owned()))
            }
        };
        while r < n && self.buf[r] == b' ' {
            r += 1;
        }
        if r == n {
            self.buf.clear();
        } else {
            self.id = r;
        }
        res
    }
    fn ne<T: FromStr>(&mut self) -> T {
        self.next::<T>().unwrap()
    }
}
0