QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#519140#8520. Xor PartitionsSocialPandaCompile Error//Rust1.4kb2024-08-14 16:35:112024-08-14 16:35:11

Judging History

你现在查看的是最新测评结果

  • [2024-08-14 16:35:11]
  • 评测
  • [2024-08-14 16:35:11]
  • 提交

answer

use std::io;
use num_bigint::BigUint;
use num_traits::{Zero, One};

const MOD: u64 = 1_000_000_007;

fn main() {
    let mut input = String::new();
    
    io::stdin().read_line(&mut input).unwrap();
    let n: usize = input.trim().parse().unwrap();
    
    input.clear();
    io::stdin().read_line(&mut input).unwrap();
    let a: Vec<u64> = input.trim().split_whitespace()
                           .map(|x| x.parse().unwrap())
                           .collect();
    
    let result = calculate_partition_sum(n, &a);
    println!("{}", result);
}

fn calculate_partition_sum(n: usize, a: &[u64]) -> BigUint {
    let mut xor_sum = vec![0u64; n + 1];
    let mut dp = vec![BigUint::zero(); n + 1];
    dp[0] = BigUint::one(); // Base case: one way to partition an empty sequence
    
    for i in 1..=n {
        xor_sum[i] = 0;
        for j in (1..=i).rev() {
            xor_sum[j] ^= a[i - 1];
            let current = dp[j - 1].clone() * BigUint::from(xor_sum[j]);
            dp[i] = (dp[i].clone() + current) % MOD;
        }
    }
    
    dp[n].clone()
}

impl std::ops::Rem<u64> for BigUint {
    type Output = BigUint;

    fn rem(self, modulus: u64) -> BigUint {
        (&self % modulus).into()
    }
}

impl<'a> std::ops::Rem<u64> for &'a BigUint {
    type Output = BigUint;

    fn rem(self, modulus: u64) -> BigUint {
        BigUint::from((self % BigUint::from(modulus)).to_u64_digits()[0])
    }
}

详细

error[E0432]: unresolved import `num_bigint`
 --> answer.code:2:5
  |
2 | use num_bigint::BigUint;
  |     ^^^^^^^^^^ maybe a missing crate `num_bigint`?
  |
  = help: consider adding `extern crate num_bigint` to use the `num_bigint` crate

error[E0432]: unresolved import `num_traits`
 --> answer.code:3:5
  |
3 | use num_traits::{Zero, One};
  |     ^^^^^^^^^^ maybe a missing crate `num_traits`?
  |
  = help: consider adding `extern crate num_traits` to use the `num_traits` crate

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0432`.