-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add atcoder/abc340/a.rs atcoder/abc340/b.rs atcoder/abc340/c.rs atcod…
…er/abc340/d.rs atcoder/abc340/remain.txt
- Loading branch information
Showing
6 changed files
with
201 additions
and
3 deletions.
There are no files selected for viewing
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,34 @@ | ||
use std::io::Read; | ||
|
||
fn get_word() -> String { | ||
let stdin = std::io::stdin(); | ||
let mut stdin=stdin.lock(); | ||
let mut u8b: [u8; 1] = [0]; | ||
loop { | ||
let mut buf: Vec<u8> = Vec::with_capacity(16); | ||
loop { | ||
let res = stdin.read(&mut u8b); | ||
if res.unwrap_or(0) == 0 || u8b[0] <= b' ' { | ||
break; | ||
} else { | ||
buf.push(u8b[0]); | ||
} | ||
} | ||
if buf.len() >= 1 { | ||
let ret = String::from_utf8(buf).unwrap(); | ||
return ret; | ||
} | ||
} | ||
} | ||
|
||
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() } | ||
|
||
fn main() { | ||
let mut a: i32 = get(); | ||
let b: i32 = get(); | ||
let d: i32 = get(); | ||
while a <= b { | ||
print!("{} ", a); | ||
a += d; | ||
} | ||
} |
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,38 @@ | ||
use std::io::Read; | ||
|
||
fn get_word() -> String { | ||
let stdin = std::io::stdin(); | ||
let mut stdin=stdin.lock(); | ||
let mut u8b: [u8; 1] = [0]; | ||
loop { | ||
let mut buf: Vec<u8> = Vec::with_capacity(16); | ||
loop { | ||
let res = stdin.read(&mut u8b); | ||
if res.unwrap_or(0) == 0 || u8b[0] <= b' ' { | ||
break; | ||
} else { | ||
buf.push(u8b[0]); | ||
} | ||
} | ||
if buf.len() >= 1 { | ||
let ret = String::from_utf8(buf).unwrap(); | ||
return ret; | ||
} | ||
} | ||
} | ||
|
||
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() } | ||
|
||
fn main() { | ||
let q: i32 = get(); | ||
let mut v = vec![]; | ||
for _ in 0..q { | ||
let ty: i32 = get(); | ||
let c: usize = get(); | ||
if ty == 1 { | ||
v.push(c); | ||
} else { | ||
println!("{}", v[v.len() - c]); | ||
} | ||
} | ||
} |
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,40 @@ | ||
use std::io::Read; | ||
|
||
fn get_word() -> String { | ||
let stdin = std::io::stdin(); | ||
let mut stdin=stdin.lock(); | ||
let mut u8b: [u8; 1] = [0]; | ||
loop { | ||
let mut buf: Vec<u8> = Vec::with_capacity(16); | ||
loop { | ||
let res = stdin.read(&mut u8b); | ||
if res.unwrap_or(0) == 0 || u8b[0] <= b' ' { | ||
break; | ||
} else { | ||
buf.push(u8b[0]); | ||
} | ||
} | ||
if buf.len() >= 1 { | ||
let ret = String::from_utf8(buf).unwrap(); | ||
return ret; | ||
} | ||
} | ||
} | ||
|
||
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() } | ||
|
||
fn main() { | ||
let mut n: u64 = get(); | ||
let mut c = 0; | ||
let mut d = 1; | ||
let mut tot = 0; | ||
while n > 1 { | ||
tot += n * d + c; | ||
if n % 2 == 1 { | ||
c = d + c; | ||
} | ||
n /= 2; | ||
d *= 2; | ||
} | ||
println!("{}", tot + c * 2); | ||
} |
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,85 @@ | ||
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 | ||
macro_rules! input { | ||
($($r:tt)*) => { | ||
let stdin = std::io::stdin(); | ||
let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); | ||
let mut next = move || -> String{ | ||
bytes.by_ref().map(|r|r.unwrap() as char) | ||
.skip_while(|c|c.is_whitespace()) | ||
.take_while(|c|!c.is_whitespace()) | ||
.collect() | ||
}; | ||
input_inner!{next, $($r)*} | ||
}; | ||
} | ||
|
||
macro_rules! input_inner { | ||
($next:expr) => {}; | ||
($next:expr,) => {}; | ||
($next:expr, $var:ident : $t:tt $($r:tt)*) => { | ||
let $var = read_value!($next, $t); | ||
input_inner!{$next $($r)*} | ||
}; | ||
} | ||
|
||
macro_rules! read_value { | ||
($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) }; | ||
($next:expr, [ $t:tt ; $len:expr ]) => { | ||
(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() | ||
}; | ||
($next:expr, usize1) => (read_value!($next, usize) - 1); | ||
($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); | ||
} | ||
|
||
// Dijkstra's algorithm. | ||
// Verified by: AtCoder ABC164 (https://atcoder.jp/contests/abc164/submissions/12423853) | ||
struct Dijkstra { | ||
edges: Vec<Vec<(usize, i64)>>, // adjacent list representation | ||
} | ||
|
||
impl Dijkstra { | ||
fn new(n: usize) -> Self { | ||
Dijkstra { edges: vec![Vec::new(); n] } | ||
} | ||
fn add_edge(&mut self, from: usize, to: usize, cost: i64) { | ||
self.edges[from].push((to, cost)); | ||
} | ||
// This function returns a Vec consisting of the distances from vertex source. | ||
fn solve(&self, source: usize, inf: i64) -> Vec<i64> { | ||
let n = self.edges.len(); | ||
let mut d = vec![inf; n]; | ||
// que holds (-distance, vertex), so that que.pop() returns the nearest element. | ||
let mut que = std::collections::BinaryHeap::new(); | ||
que.push((0, source)); | ||
while let Some((cost, pos)) = que.pop() { | ||
let cost = -cost; | ||
if d[pos] <= cost { | ||
continue; | ||
} | ||
d[pos] = cost; | ||
for &(w, c) in &self.edges[pos] { | ||
let newcost = cost + c; | ||
if d[w] > newcost { | ||
d[w] = newcost + 1; | ||
que.push((-newcost, w)); | ||
} | ||
} | ||
} | ||
return d; | ||
} | ||
} | ||
|
||
fn main() { | ||
input! { | ||
n: usize, | ||
abx: [(i64, i64, usize1); n - 1], | ||
} | ||
let mut dijk = Dijkstra::new(n); | ||
for i in 0..n - 1 { | ||
let (a, b, x) = abx[i]; | ||
dijk.add_edge(i, i + 1, a); | ||
dijk.add_edge(i, x, b); | ||
} | ||
let sol = dijk.solve(0, 1i64 << 60); | ||
println!("{}", sol[n - 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,3 @@ | ||
e | ||
f | ||
g |
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