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
11 changed files
with
432 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,14 @@ | ||
[package] | ||
name = "abc276" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
# dependencies added to new project | ||
[dependencies] | ||
num = "=0.2.1" | ||
proconio = { version = "=0.3.6", 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.42.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,15 @@ | ||
use proconio::{input, marker::Chars}; | ||
|
||
fn main() { | ||
input! { | ||
s: Chars, | ||
}; | ||
let n = s.len(); | ||
let ans = s | ||
.iter() | ||
.rev() | ||
.position(|&c| c == 'a') | ||
.map(|i| (n - 1 - i) as i64 + 1) | ||
.unwrap_or(-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,28 @@ | ||
use proconio::{input, marker::Usize1}; | ||
|
||
fn main() { | ||
input! { | ||
n: usize, | ||
m: usize, | ||
ab: [(Usize1, Usize1); m], | ||
}; | ||
let mut edges = vec![vec![]; n]; | ||
for (u, v) in ab.iter().copied() { | ||
edges[u].push(v); | ||
edges[v].push(u); | ||
} | ||
|
||
for u in 0..n { | ||
let mut e_u = edges[u].iter().copied().collect::<Vec<usize>>(); | ||
e_u.sort(); | ||
print!("{}", e_u.len()); | ||
if !e_u.is_empty() { | ||
print!(" "); | ||
for (i, v) in e_u.iter().copied().enumerate() { | ||
print!("{}{}", v + 1, if i == e_u.len() - 1 { '\n' } else { ' ' }); | ||
} | ||
} else { | ||
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,14 @@ | ||
use proconio::input; | ||
use superslice::Ext; | ||
|
||
fn main() { | ||
input! { | ||
n: usize, | ||
mut p: [usize; n], | ||
}; | ||
|
||
p.prev_permutation(); | ||
for (i, p_i) in p.iter().copied().enumerate() { | ||
print!("{}{}", p_i, if i == n - 1 { '\n' } else { ' ' }); | ||
} | ||
} |
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,89 @@ | ||
use std::collections::{HashMap, HashSet}; | ||
|
||
use proconio::input; | ||
|
||
fn prime_factorization(n: usize) -> HashMap<usize, usize> { | ||
let mut p = HashMap::new(); | ||
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.insert(i, c); | ||
} | ||
} | ||
if n != 1 { | ||
p.insert(n, 1); | ||
} | ||
p | ||
} | ||
|
||
fn main() { | ||
input! { | ||
n: usize, | ||
a: [usize; n], | ||
}; | ||
|
||
let mut ok = true; | ||
for i in 1..n { | ||
if a[i] != a[0] { | ||
ok = false; | ||
} | ||
} | ||
if ok { | ||
println!("0"); | ||
return; | ||
} | ||
|
||
let mut maps = vec![]; | ||
for a_i in a.iter().copied() { | ||
let map = prime_factorization(a_i); | ||
maps.push(map); | ||
} | ||
|
||
let mut ok = true; | ||
let mut map_a_0 = prime_factorization(a[0]); | ||
map_a_0.remove(&2); | ||
map_a_0.remove(&3); | ||
let set_a_0 = map_a_0.keys().collect::<HashSet<_>>(); | ||
let mut min_2 = 1_000_000_000; | ||
let mut min_3 = 1_000_000_000; | ||
for m in maps.iter() { | ||
let mut map = m.clone(); | ||
min_2 = min_2.min(*m.get(&2).unwrap_or(&0)); | ||
min_3 = min_3.min(*m.get(&3).unwrap_or(&0)); | ||
map.remove(&2); | ||
map.remove(&3); | ||
let set = map.keys().collect::<HashSet<_>>(); | ||
if set_a_0.len() != set.len() { | ||
ok = false; | ||
break; | ||
} | ||
if set_a_0 != set { | ||
ok = false; | ||
break; | ||
} | ||
} | ||
if !ok { | ||
println!("-1"); | ||
return; | ||
} | ||
|
||
let mut count = 0_usize; | ||
for m in maps.iter() { | ||
count += *m.get(&2).unwrap_or(&0) - min_2; | ||
count += *m.get(&3).unwrap_or(&0) - min_3; | ||
} | ||
|
||
let ans = count; | ||
println!("{}", ans); | ||
} |
Oops, something went wrong.