diff --git a/cargo-atcoder-1.70.0/contests/abc342/Cargo.lock b/cargo-atcoder-1.70.0/contests/abc342/Cargo.lock new file mode 100644 index 00000000..5e1e1e5a --- /dev/null +++ b/cargo-atcoder-1.70.0/contests/abc342/Cargo.lock @@ -0,0 +1,168 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "abc342" +version = "0.1.0" +dependencies = [ + "ac-library-rs", + "num", + "proconio", + "superslice", +] + +[[package]] +name = "ac-library-rs" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09e1ead7b72f44698f97266946c0576d00c9e2010858f5aba47aa4660177ef73" + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "num" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43db66d1170d347f9a065114077f7dccb00c1b9478c89384490a3425279a4606" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-complex" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23c6602fda94a57c990fe0df199a035d83576b496aa29f4e634a8ac6004e68a6" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d869c01cc0c455284163fd0092f1f93835385ccab5a98a0dcc497b2f8bf055a9" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +dependencies = [ + "autocfg", + "num-bigint", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "proc-macro2" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "proconio" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91c333be3af2936f8e810300bc74fe4d0cc168ebc04ab02a28c5b1060fa1bd59" +dependencies = [ + "lazy_static", + "proconio-derive", +] + +[[package]] +name = "proconio-derive" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bccfa078f1a3db6563793531989799a2201d9bdf609f48dd82620b443fbcd409" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "superslice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab16ced94dbd8a46c82fd81e3ed9a8727dac2977ea869d217bcc4ea1f122e81f" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/cargo-atcoder-1.70.0/contests/abc342/Cargo.toml b/cargo-atcoder-1.70.0/contests/abc342/Cargo.toml new file mode 100644 index 00000000..d54c0f03 --- /dev/null +++ b/cargo-atcoder-1.70.0/contests/abc342/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "abc342" +version = "0.1.0" +edition = "2021" + +# dependencies added to new project +[dependencies] +ac-library-rs = "=0.1.1" +num = "=0.4.0" +proconio = { version = "=0.4.3", features = ["derive"] } +superslice = "=1.0.0" + +[profile.release] +lto = true +panic = 'abort' diff --git a/cargo-atcoder-1.70.0/contests/abc342/rust-toolchain b/cargo-atcoder-1.70.0/contests/abc342/rust-toolchain new file mode 100644 index 00000000..9006c0b4 --- /dev/null +++ b/cargo-atcoder-1.70.0/contests/abc342/rust-toolchain @@ -0,0 +1 @@ +1.70.0 \ No newline at end of file diff --git a/cargo-atcoder-1.70.0/contests/abc342/src/bin/a.rs b/cargo-atcoder-1.70.0/contests/abc342/src/bin/a.rs new file mode 100644 index 00000000..5fc8aa8f --- /dev/null +++ b/cargo-atcoder-1.70.0/contests/abc342/src/bin/a.rs @@ -0,0 +1,21 @@ +use std::collections::HashMap; + +use proconio::{input, marker::Chars}; + +fn main() { + input! { + s: Chars, + }; + let mut map = HashMap::new(); + for s_i in s.iter().copied() { + *map.entry(s_i).or_insert(0) += 1; + } + let mut min = (1_usize << 60, ' '); + for (k, v) in map { + if v < min.0 { + min = (v, k); + } + } + let ans = s.iter().position(|c| c == &min.1).unwrap() + 1; + println!("{}", ans); +} diff --git a/cargo-atcoder-1.70.0/contests/abc342/src/bin/b.rs b/cargo-atcoder-1.70.0/contests/abc342/src/bin/b.rs new file mode 100644 index 00000000..121aba02 --- /dev/null +++ b/cargo-atcoder-1.70.0/contests/abc342/src/bin/b.rs @@ -0,0 +1,20 @@ +use proconio::{input, marker::Usize1}; + +fn main() { + input! { + n: usize, + p: [Usize1; n], + q: usize, + ab: [(Usize1, Usize1); q] + }; + + let mut ip = p + .iter() + .copied() + .enumerate() + .collect::>(); + ip.sort_by_key(|&(_, v)| v); + for (a, b) in ab { + println!("{}", if ip[a].0 < ip[b].0 { a + 1 } else { b + 1 }); + } +} diff --git a/cargo-atcoder-1.70.0/contests/abc342/src/bin/c.rs b/cargo-atcoder-1.70.0/contests/abc342/src/bin/c.rs new file mode 100644 index 00000000..4ee289e5 --- /dev/null +++ b/cargo-atcoder-1.70.0/contests/abc342/src/bin/c.rs @@ -0,0 +1,33 @@ +use proconio::{input, marker::Chars}; + +fn main() { + input! { + _n: usize, + s: Chars, + q: usize, + cd: [(char, char); q], + }; + let s = s + .iter() + .copied() + .map(|c| (c as u8 - b'a') as usize) + .collect::>(); + let cd = cd + .iter() + .copied() + .map(|(c, d)| ((c as u8 - b'a') as usize, (d as u8 - b'a') as usize)) + .collect::>(); + let mut table = (0..26).collect::>(); + for (c, d) in cd { + for i in 0..26 { + if table[i] == c { + table[i] = d; + } + } + } + for s_i in s { + let c = table[s_i]; + print!("{}", (c as u8 + b'a') as char); + } + println!(); +} diff --git a/cargo-atcoder-1.70.0/contests/abc342/src/bin/d.rs b/cargo-atcoder-1.70.0/contests/abc342/src/bin/d.rs new file mode 100644 index 00000000..1dedc0dd --- /dev/null +++ b/cargo-atcoder-1.70.0/contests/abc342/src/bin/d.rs @@ -0,0 +1,75 @@ +use std::collections::BTreeMap; + +use proconio::input; +use superslice::Ext; + +fn prime_factorization(n: usize) -> Vec<(usize, usize)> { + let mut p = vec![]; + if n < 2 { + return p; + } + let mut n = n; // shadowing + for i in 2.. { + if i * i > n { + break; + } + let mut c = 0; + while n % i == 0 { + c += 1; + n /= i; + } + if c > 0 { + p.push((i, c)); + } + } + if n != 1 { + p.push((n, 1)); + } + p +} + +fn main() { + input! { + n: usize, + a: [usize; n], + }; + + let mut group = vec![]; + let mut groups = BTreeMap::new(); + for (i, a_i) in a.iter().copied().enumerate() { + if a_i == 0 { + group.push(0); + continue; + } + let ps = prime_factorization(a_i); + let mut product = 1_usize; + for (p, c) in ps { + if c % 2 == 0 { + continue; + } + product *= p; + } + group.push(product); + groups.entry(product).or_insert_with(Vec::new).push(i); + } + groups.entry(1).or_insert_with(Vec::new); + let mut zeros = vec![0; n + 1]; + for (i, a_i) in a.iter().copied().enumerate().rev() { + zeros[i] = zeros[i + 1] + if a_i == 0 { 1 } else { 0 }; + } + + // println!("{:?}", groups); + // println!("{:?}", zeros); + let mut ans = 0_usize; + for (i, g) in group.iter().copied().enumerate() { + let count = if g == 0 { + n - 1 - i + } else { + let is = &groups[&g]; + is.len() - 1 - is.lower_bound(&i) + zeros[i] + }; + // println!("{} {}", a[i], count); + ans += count; + } + println!("{}", ans); +} diff --git a/cargo-atcoder-1.70.0/contests/abc342/src/bin/e.rs b/cargo-atcoder-1.70.0/contests/abc342/src/bin/e.rs new file mode 100644 index 00000000..315ebde8 --- /dev/null +++ b/cargo-atcoder-1.70.0/contests/abc342/src/bin/e.rs @@ -0,0 +1,54 @@ +use std::collections::BinaryHeap; + +use proconio::{input, marker::Usize1}; + +fn main() { + input! { + n: usize, + m: usize, + ldkcab: [(i64, i64, i64, i64, Usize1, Usize1); m], + }; + let mut rev_edges = vec![vec![]; n]; + for (l, d, k, c, a, b) in ldkcab { + rev_edges[b].push((a, l, d, k, c)); + } + + let inf = 1_i64 << 60; + let mut f = vec![-inf; n]; + for (_, l, d, k, c) in rev_edges[n - 1].iter().copied() { + let w = l + (k - 1) * d + c; + f[n - 1] = f[n - 1].max(w); + } + if f[n - 1] == -inf { + for _ in 0..n - 1 { + println!("Unreachable"); + } + return; + } + let mut pq = BinaryHeap::new(); + pq.push((f[n - 1], n - 1)); + while let Some((w_u, u)) = pq.pop() { + if w_u < f[u] { + continue; + } + for (v, l, d, k, c) in rev_edges[u].iter().copied() { + if w_u < l + c { + continue; + } + let w = ((w_u - c - l) / d).min(k - 1) * d + l; + if w > f[v] { + f[v] = w; + pq.push((w, v)); + } + } + } + + for a in 0..n - 1 { + let ans = if f[a] == -inf { + "Unreachable".to_string() + } else { + f[a].to_string() + }; + println!("{}", ans); + } +} diff --git a/cargo-atcoder-1.70.0/contests/abc342/src/bin/f.rs b/cargo-atcoder-1.70.0/contests/abc342/src/bin/f.rs new file mode 100644 index 00000000..2a9506c8 --- /dev/null +++ b/cargo-atcoder-1.70.0/contests/abc342/src/bin/f.rs @@ -0,0 +1,10 @@ +use proconio::{input, marker::Usize1}; + +fn main() { + input! { + n: usize, + a: [Usize1; n], + }; + let ans = n - a.len(); + println!("{}", ans); +} diff --git a/cargo-atcoder-1.70.0/contests/abc342/src/bin/g.rs b/cargo-atcoder-1.70.0/contests/abc342/src/bin/g.rs new file mode 100644 index 00000000..2a9506c8 --- /dev/null +++ b/cargo-atcoder-1.70.0/contests/abc342/src/bin/g.rs @@ -0,0 +1,10 @@ +use proconio::{input, marker::Usize1}; + +fn main() { + input! { + n: usize, + a: [Usize1; n], + }; + let ans = n - a.len(); + println!("{}", ans); +}