Skip to content

Commit

Permalink
Add atcoder/abc365/a.rs atcoder/abc365/b.rs atcoder/abc365/c.rs atcod…
Browse files Browse the repository at this point in the history
…er/abc365/remain.txt
  • Loading branch information
koba-e964 committed Nov 9, 2024
1 parent 24d79db commit 132ea01
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
10 changes: 10 additions & 0 deletions atcoder/abc365/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().trim().parse::<i64>().unwrap();
println!("{}", 365 + ((y % 400 == 0) ^ (y % 100 == 0) ^ (y % 4 == 0)) as i32);
}
40 changes: 40 additions & 0 deletions atcoder/abc365/b.rs
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 n: usize = get();
let mut a: Vec<i64> = vec![0; n];
for i in 0..n {
a[i] = get();
}
let mut b = a.clone();
b.sort();
for i in 0..n {
if a[i] == b[n - 2] {
println!("{}", i + 1);
return;
}
}
}
53 changes: 53 additions & 0 deletions atcoder/abc365/c.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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 m: i64 = get();
let mut a: Vec<i64> = vec![0; n];
for i in 0..n {
a[i] = get();
}
let asum = a.iter().sum::<i64>();
if asum <= m {
println!("infinite");
return;
}
let mut pass = 0;
let mut fail = 1 << 30;
while fail - pass > 1 {
let mid = (pass + fail) / 2;
let mut sum = 0;
for i in 0..n {
sum += a[i].min(mid);
}
if sum <= m {
pass = mid;
} else {
fail = mid;
}
}
println!("{pass}");
}
4 changes: 4 additions & 0 deletions atcoder/abc365/remain.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
d
e
f
g

0 comments on commit 132ea01

Please sign in to comment.