Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sample code for the practice contest #52

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

TonalidadeHidrica
Copy link
Collaborator

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

Copy link
Contributor

@matsu7874 matsu7874 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For convenience, how about adding it?

examples/practice2_a_disjoint_set_union.rs Show resolved Hide resolved
examples/practice2_b_fenwick_tree.rs Show resolved Hide resolved
examples/practice2_c_floor_sum.rs Show resolved Hide resolved
examples/practice2_e_mincostflow.rs Show resolved Hide resolved
examples/practice2_g_scc.rs Show resolved Hide resolved
examples/practice2_h_two_sat.rs Show resolved Hide resolved
examples/practice2_i_number_of_substrings.rs Show resolved Hide resolved
@TonalidadeHidrica
Copy link
Collaborator Author

@matsu7874 Applied!

@qryxip
Copy link
Member

qryxip commented Oct 4, 2020

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

@TonalidadeHidrica
Copy link
Collaborator Author

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

@TonalidadeHidrica
Copy link
Collaborator Author

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

@mizar
Copy link
Collaborator

mizar commented Mar 27, 2023

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();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants