Giter Club home page Giter Club logo

Comments (4)

fukatani avatar fukatani commented on May 27, 2024

(M-1-2+1) as usize
を単純にusizeのM-1-2+1とすると、underflowになってしまうので、そこは考えなければ。

from atcoder-tools.

fukatani avatar fukatani commented on May 27, 2024
use io::*;
use std::*;

const MOD: i64 = 123;
const YES: &'static str = "yes";
const NO: &'static str = "NO";
fn solve(N: i64, M: i64, H: Vec<Vec<String>>, A: Vec<i64>, B: Vec<f64>, Q: i64, X: Vec<i64>) {}

fn main() {
    let con = read_string();
    let mut scanner = Scanner::new(&con);
    let N: i64 = scanner.next();
    let M: i64 = scanner.next();
    let H: Vec<Vec<String>> = (0..(N - 2 + 1) as usize)
        .map(|_| {
            (0..(M - 1 - 2 + 1) as usize)
                .map(|_| scanner.next())
                .collect::<Vec<_>>()
        })
        .collect::<Vec<_>>();
    let mut A: Vec<i64> = vec![0i64; (N - 2 + 1) as usize];
    let mut B: Vec<f64> = vec![0f64; (N - 2 + 1) as usize];
    for i in 0..(N - 2 + 1) as usize {
        A[i] = scanner.next();
        B[i] = scanner.next();
    }
    let Q: i64 = scanner.next();
    let X: Vec<i64> = (0..(M + Q) as usize)
        .map(|_| scanner.next())
        .collect::<Vec<_>>();
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(move || solve(N, M, H, A, B, Q, X))
        .unwrap()
        .join()
        .unwrap();
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}

mutを消すとこうなる、ただvectorはcollectするより最初に容量確保する今の実装の方が速いかも。

from atcoder-tools.

kyuridenamida avatar kyuridenamida commented on May 27, 2024

Rustわからないんですが、途中式で負数が出てくるとエラーになってしまいますか?
だとしたら多分アンダーフローとかはSymPy等導入してきちんと式整理したほうが良いという提案をkimiyukiさんから受けたので、検討します。

from atcoder-tools.

fukatani avatar fukatani commented on May 27, 2024

そうです、usizeの計算中にマイナスになるとabortされます。

Issue立てたものの、いつ取り掛かれるかわからないので、私の方は気にせず、sympyが必要になれば導入してください。

from atcoder-tools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.