結果

問題 No.685 Logical Operations
ユーザー koba-e964koba-e964
提出日時 2021-11-17 02:15:48
言語 Rust
(1.77.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,684 bytes
コンパイル時間 844 ms
コンパイル使用メモリ 154,900 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 08:46:43
合計ジャッジ時間 2,010 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 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,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::*;
use std::collections::*;
use std::io::Read;

fn get_word() -> String {
    let stdin = std::io::stdin();
    let mut stdin=stdin.lock();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

const MOD: i64 = 1_000_000_007;

// 0 <= x <= n, 0 <= y <= m
fn dfs(n: i64, m: i64, axeq: bool, xoeq: bool, memo: &mut HashMap<(i64, i64, bool, bool), i64>) -> i64 {
    if n == 0 && m == 0 {
        return if axeq && xoeq {
            1
        } else {
            0
        };
    }
    let key = (n, m, axeq, xoeq);
    if let Some(&val) = memo.get(&key) {
        return val;
    }
    let mut ans = 0;
    for a in 0..min(2, n + 1) {
        for b in 0..min(2, m + 1) {
            let naxeq = (a & b, true) <= (a ^ b, axeq);
            let noxeq = (a ^ b, true) <= (a | b, xoeq);
            ans += dfs((n - a) / 2, (m - b) / 2, naxeq, noxeq, memo);
            if ans >= MOD {
                ans -= MOD;
            }
        }
    }
    memo.insert(key, ans);
    ans
}

// Tags: digital-dp
fn main() {
    let n: i64 = get();
    let mut memo = HashMap::new();
    let res = dfs(n, n, false, false, &mut memo);
    let inv2 = (MOD + 1) / 2;
    println!("{}", res * inv2 % MOD);
}
0