Skip to content

Commit

Permalink
Add atcoder/abc374/a.rs atcoder/abc374/b.rs atcoder/abc374/c.rs atcod…
Browse files Browse the repository at this point in the history
…er/abc374/remain.txt
  • Loading branch information
koba-e964 committed Nov 9, 2024
1 parent 132ea01 commit 4d24251
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
10 changes: 10 additions & 0 deletions atcoder/abc374/a.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn getline() -> String {
let mut ret = String::new();
std::io::stdin().read_line(&mut ret).ok().unwrap();
ret
}

fn main() {
let y = getline().ends_with("san\n");
println!("{}", if y { "Yes" } else { "No" });
}
17 changes: 17 additions & 0 deletions atcoder/abc374/b.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
fn getline() -> String {
let mut ret = String::new();
std::io::stdin().read_line(&mut ret).ok().unwrap();
ret
}

fn main() {
let a = getline().chars().collect::<Vec<_>>();
let b = getline().chars().collect::<Vec<_>>();
for i in 0..a.len().min(b.len()) {
if a[i] != b[i] {
println!("{}", i + 1);
return;
}
}
println!("0");
}
44 changes: 44 additions & 0 deletions atcoder/abc374/c.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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 n: usize = get();
let mut a: Vec<i64> = vec![0; n];
for i in 0..n {
a[i] = get();
}
let asum: i64 = a.iter().sum();
let mut ans: i64 = asum;
for bits in 0..1 << n {
let mut sum: i64 = 0;
for i in 0..n {
if bits & 1 << i != 0 {
sum += a[i];
}
}
ans = ans.min(sum.max(asum - sum));
}
println!("{ans}");
}
4 changes: 4 additions & 0 deletions atcoder/abc374/remain.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
d
e
f
g

0 comments on commit 4d24251

Please sign in to comment.