Skip to content

Commit

Permalink
abc223 a, b, c, d
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Oct 25, 2023
1 parent ffd8963 commit 1113469
Show file tree
Hide file tree
Showing 11 changed files with 369 additions and 0 deletions.
169 changes: 169 additions & 0 deletions cargo-atcoder-1.70.0/contests/abc223/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions cargo-atcoder-1.70.0/contests/abc223/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "abc223"
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'
1 change: 1 addition & 0 deletions cargo-atcoder-1.70.0/contests/abc223/rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.70.0
9 changes: 9 additions & 0 deletions cargo-atcoder-1.70.0/contests/abc223/src/bin/a.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use proconio::input;

fn main() {
input! {
x: usize,
}
let ans = x >= 100 && x % 100 == 0;
println!("{}", if ans { "Yes" } else { "No" });
}
21 changes: 21 additions & 0 deletions cargo-atcoder-1.70.0/contests/abc223/src/bin/b.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use proconio::{input, marker::Chars};

fn main() {
input! {
mut s: Chars,
};
let mut min = s.clone();
let mut max = s.clone();
let n = s.len();
for _ in 0..n {
if s < min {
min = s.clone();
}
if s > max {
max = s.clone();
}
s.rotate_left(1);
}
println!("{}", min.into_iter().collect::<String>());
println!("{}", max.into_iter().collect::<String>());
}
58 changes: 58 additions & 0 deletions cargo-atcoder-1.70.0/contests/abc223/src/bin/c.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use proconio::input;

fn main() {
input! {
n: usize,
ab: [(i64, i64); n],
};
let sum_a = ab.iter().map(|&(a_i, _)| a_i).sum::<i64>();
let mut ok = 0_f64;
let mut ng = 1e18_f64;
for _ in 0..100 {
let s = ok + (ng - ok) / 2_f64;
let mut s_l = 0_f64;
let mut l = 0_f64;
for (a_i, b_i) in ab.iter().copied() {
let s_i = a_i as f64 / b_i as f64;
if s_l + s_i <= s {
s_l += s_i;
l += a_i as f64;
} else {
l += (s - s_l) * b_i as f64;
break;
}
}
let mut s_r = 0_f64;
let mut r = sum_a as f64;
for (a_i, b_i) in ab.iter().copied().rev() {
let s_i = a_i as f64 / b_i as f64;
if s_r + s_i <= s {
s_r += s_i;
r -= a_i as f64;
} else {
r -= (s - s_r) * b_i as f64;
break;
}
}
if l <= r {
ok = s;
} else {
ng = s;
}
}
let s = ng;
let mut s_l = 0_f64;
let mut l = 0_f64;
for (a_i, b_i) in ab.iter().copied() {
let s_i = a_i as f64 / b_i as f64;
if s_l + s_i <= s {
s_l += s_i;
l += a_i as f64;
} else {
l += (s - s_l) * b_i as f64;
break;
}
}
let ans = l;
println!("{}", ans);
}
56 changes: 56 additions & 0 deletions cargo-atcoder-1.70.0/contests/abc223/src/bin/d.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use std::{cmp::Reverse, collections::BinaryHeap};

use proconio::{input, marker::Usize1};

fn topological_sort(e: &[Vec<usize>]) -> Option<Vec<usize>> {
let n = e.len();
let mut c_in = vec![0; n];
for e_u in e.iter() {
for &v in e_u.iter() {
c_in[v] += 1;
}
}
// u の小さいものを取り出す
let mut pq = BinaryHeap::new();
for u in 0..n {
if c_in[u] == 0 {
pq.push(Reverse(u));
}
}
let mut res = vec![];
while let Some(Reverse(u)) = pq.pop() {
res.push(u);
for &v in e[u].iter() {
c_in[v] -= 1;
if c_in[v] == 0 {
pq.push(Reverse(v));
}
}
}
if res.len() == n {
Some(res)
} else {
None
}
}

fn main() {
input! {
n: usize,
m: usize,
ab: [(Usize1, Usize1); m],
};

let mut edges = vec![vec![]; n];
for (a, b) in ab {
edges[a].push(b);
}

if let Some(sorted) = topological_sort(&edges) {
for u in sorted {
println!("{}", u + 1);
}
} else {
println!("-1");
}
}
10 changes: 10 additions & 0 deletions cargo-atcoder-1.70.0/contests/abc223/src/bin/e.rs
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);
}
10 changes: 10 additions & 0 deletions cargo-atcoder-1.70.0/contests/abc223/src/bin/f.rs
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);
}
10 changes: 10 additions & 0 deletions cargo-atcoder-1.70.0/contests/abc223/src/bin/g.rs
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);
}
10 changes: 10 additions & 0 deletions cargo-atcoder-1.70.0/contests/abc223/src/bin/h.rs
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);
}

0 comments on commit 1113469

Please sign in to comment.