ac-library-rs icon indicating copy to clipboard operation
ac-library-rs copied to clipboard

Add sample code for the practice contest

Open TonalidadeHidrica opened this issue 5 years ago • 5 comments

Added all the sample code for AtCoder Library Practice Contest except for Convolution. These examples may also be useful for expander checker.

TonalidadeHidrica avatar Sep 16 '20 07:09 TonalidadeHidrica

@matsu7874 Applied!

TonalidadeHidrica avatar Oct 02 '20 16:10 TonalidadeHidrica

Why not add an example for F? We've already implemented convolution.

qryxip avatar Oct 04 '20 07:10 qryxip

@qryxip I didn't just because it was not yet merged when I created this PR. I'l do it later.

TonalidadeHidrica avatar Oct 04 '20 07:10 TonalidadeHidrica

Examples do not affect language updates; triaged as low priority.

TonalidadeHidrica avatar Mar 26 '23 20:03 TonalidadeHidrica

Why not add an example for F? We've already implemented convolution.

@qryxip I didn't just because it was not yet merged when I created this PR. I'l do it later.

For example, practice2_f might be implemented as follows.

https://atcoder.jp/contests/practice2/submissions/40093355

// Check Problem Statement via https://atcoder.jp/contests/practice2/tasks/practice2_f
use ac_library_rs::{convolution, modint::ModInt998244353 as Mint};
use std::io::prelude::*;

pub fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    let n: usize = input.next().unwrap().parse().unwrap();
    let m: usize = input.next().unwrap().parse().unwrap();
    let a: Vec<Mint> = input
        .by_ref()
        .take(n)
        .map(str::parse)
        .map(Result::unwrap)
        .collect();
    let b: Vec<Mint> = input
        .by_ref()
        .take(m)
        .map(str::parse)
        .map(Result::unwrap)
        .collect();

    print_oneline(convolution::convolution(&a, &b));
}

fn print_oneline<I: IntoIterator<Item = T>, T: std::fmt::Display>(values: I) {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    for (i, v) in values.into_iter().enumerate() {
        if i == 0 {
            write!(&mut out, "{}", v).unwrap();
        } else {
            write!(&mut out, " {}", v).unwrap();
        }
    }
    writeln!(&mut out).unwrap();
}

mizar avatar Mar 27 '23 05:03 mizar