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
388 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 = "abc277" | ||
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,11 @@ | ||
use proconio::input; | ||
|
||
fn main() { | ||
input! { | ||
n: usize, | ||
x: usize, | ||
p: [usize; n], | ||
}; | ||
let ans = p.iter().position(|p_i| p_i == &x).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 std::collections::HashSet; | ||
|
||
use proconio::{input, marker::Chars}; | ||
|
||
fn main() { | ||
input! { | ||
n: usize, | ||
s: [Chars; n], | ||
}; | ||
let cs1 = "HDCS".chars().collect::<Vec<char>>(); | ||
let cs2 = "A23456789TJQK".chars().collect::<Vec<char>>(); | ||
let mut set = HashSet::new(); | ||
for s_i in s { | ||
if !cs1.contains(&s_i[0]) || !cs2.contains(&s_i[1]) || !set.insert(s_i) { | ||
println!("No"); | ||
return; | ||
} | ||
} | ||
println!("Yes"); | ||
} |
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,51 @@ | ||
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque}; | ||
|
||
use proconio::{input, marker::Usize1}; | ||
|
||
fn main() { | ||
input! { | ||
n: usize, | ||
ab: [(Usize1, Usize1); n], | ||
}; | ||
let map = ab | ||
.iter() | ||
.copied() | ||
.map(|(a, _)| a) | ||
.chain(ab.iter().copied().map(|(_, b)| b)) | ||
.chain(std::iter::once(0)) | ||
.collect::<BTreeSet<_>>() | ||
.into_iter() | ||
.enumerate() | ||
.fold(BTreeMap::new(), |mut m, (i, k)| { | ||
m.insert(k, i); | ||
m | ||
}); | ||
let mut rev = HashMap::new(); | ||
for (k, v) in map.iter() { | ||
rev.insert(v, k); | ||
} | ||
|
||
let mut edges = vec![vec![]; map.len()]; | ||
for (u, v) in ab.iter().copied() { | ||
edges[map[&u]].push(map[&v]); | ||
edges[map[&v]].push(map[&u]); | ||
} | ||
|
||
let mut max = 0_usize; | ||
let mut used = HashSet::new(); | ||
let mut deque = VecDeque::new(); | ||
used.insert(0); | ||
deque.push_back(0); | ||
while let Some(u) = deque.pop_front() { | ||
for v in edges[u].iter().copied() { | ||
if !used.insert(v) { | ||
continue; | ||
} | ||
deque.push_back(v); | ||
max = max.max(v); | ||
} | ||
} | ||
|
||
let ans = *rev.get(&max).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,48 @@ | ||
use std::collections::HashMap; | ||
|
||
use proconio::input; | ||
|
||
fn main() { | ||
input! { | ||
n: usize, | ||
m: usize, | ||
a: [usize; n], | ||
}; | ||
|
||
let mut map = HashMap::new(); | ||
for a_i in a { | ||
*map.entry(a_i).or_insert(0) += 1_usize; | ||
} | ||
if map.len() == m { | ||
println!("0"); | ||
return; | ||
} | ||
let min_count = if map.len() < m { | ||
0 | ||
} else { | ||
*map.iter().map(|(_, v)| v).min().unwrap() | ||
}; | ||
let mut xs = vec![]; | ||
let mut sum = 0_usize; | ||
for (k, v) in map.iter() { | ||
sum += (*v - min_count) * *k; | ||
xs.push(*k); | ||
} | ||
xs.sort(); | ||
|
||
let mut group_sum = vec![0]; | ||
for x in xs.iter().copied() { | ||
let prev = (m + x - 1) % m; | ||
if !map.contains_key(&prev) { | ||
group_sum.push(0); | ||
} | ||
let index = group_sum.len() - 1; | ||
group_sum[index] += map.get(&x).unwrap() * x; | ||
} | ||
if xs[0] == 0 && xs[xs.len() - 1] == m - 1 && group_sum.len() > 1 { | ||
group_sum[0] += group_sum[group_sum.len() - 1]; | ||
} | ||
|
||
let ans = sum - group_sum.iter().max().unwrap(); | ||
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,52 @@ | ||
use proconio::{input, marker::Usize1}; | ||
|
||
fn dijkstra(n: usize, inf: u64, e: &[Vec<(usize, u64)>], s: usize) -> Vec<u64> { | ||
use std::{cmp::Reverse, collections::BinaryHeap}; | ||
let mut d = vec![inf; n]; | ||
let mut pq = BinaryHeap::new(); | ||
d[s] = 0; | ||
pq.push(Reverse((0, s))); | ||
while let Some(Reverse((w_u, u))) = pq.pop() { | ||
if w_u > d[u] { | ||
continue; | ||
} | ||
for (v, w_v) in e[u].iter().copied() { | ||
let w = w_u + w_v; | ||
if w < d[v] { | ||
d[v] = w; | ||
pq.push(Reverse((w, v))); | ||
} | ||
} | ||
} | ||
d | ||
} | ||
|
||
fn main() { | ||
input! { | ||
n: usize, | ||
m: usize, | ||
k: usize, | ||
uva: [(Usize1, Usize1, usize); m], | ||
s: [Usize1; k], | ||
}; | ||
let mut edges = vec![vec![]; 2 * n]; | ||
for (u, v, a) in uva { | ||
edges[u + a * n].push((v + a * n, 1)); | ||
edges[v + a * n].push((u + a * n, 1)); | ||
} | ||
for s_i in s { | ||
edges[s_i].push((s_i + n, 0)); | ||
edges[s_i + n].push((s_i, 0)); | ||
} | ||
|
||
let inf = 1_u64 << 60; | ||
let d = dijkstra(2 * n, inf, &edges, n); | ||
let on = d[n - 1]; | ||
let off = d[2 * n - 1]; | ||
let ans = if on == inf && off == inf { | ||
-1 | ||
} else { | ||
on.min(off) as i64 | ||
}; | ||
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,10 @@ | ||
use proconio::{input, marker::Usize1}; | ||
|
||
fn main() { | ||
input! { | ||
n: usize, | ||
a: [Usize1; n], | ||
}; | ||
let ans = n - a.len(); | ||
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,10 @@ | ||
use proconio::{input, marker::Usize1}; | ||
|
||
fn main() { | ||
input! { | ||
n: usize, | ||
a: [Usize1; n], | ||
}; | ||
let ans = n - a.len(); | ||
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,10 @@ | ||
use proconio::{input, marker::Usize1}; | ||
|
||
fn main() { | ||
input! { | ||
n: usize, | ||
a: [Usize1; n], | ||
}; | ||
let ans = n - a.len(); | ||
println!("{}", ans); | ||
} |