Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
407 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.70.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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::<Vec<(usize, usize)>>(); | ||
ip.sort_by_key(|&(_, v)| v); | ||
for (a, b) in ab { | ||
println!("{}", if ip[a].0 < ip[b].0 { a + 1 } else { b + 1 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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::<Vec<usize>>(); | ||
let cd = cd | ||
.iter() | ||
.copied() | ||
.map(|(c, d)| ((c as u8 - b'a') as usize, (d as u8 - b'a') as usize)) | ||
.collect::<Vec<(usize, usize)>>(); | ||
let mut table = (0..26).collect::<Vec<usize>>(); | ||
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!(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
Oops, something went wrong.