Skip to content

Commit

Permalink
Add atcoder/abc327/a.rs atcoder/abc327/b.rs atcoder/abc327/c.rs atcod…
Browse files Browse the repository at this point in the history
…er/abc327/d.rs atcoder/abc327/e.rs atcoder/abc327/remain.txt atcoder/abc330/a.rs atcoder/abc330/b.rs atcoder/abc330/c.rs atcoder/abc330/d.rs atcoder/abc330/e.rs atcoder/abc330/f.rs atcoder/abc330/remain.txt
  • Loading branch information
koba-e964 committed Apr 19, 2024
1 parent 263ce45 commit aad9422
Show file tree
Hide file tree
Showing 13 changed files with 716 additions and 0 deletions.
11 changes: 11 additions & 0 deletions atcoder/abc327/a.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fn getline() -> String {
let mut ret = String::new();
std::io::stdin().read_line(&mut ret).ok().unwrap();
ret
}

fn main() {
getline();
let s = getline();
println!("{}", if s.contains("ab") || s.contains("ba") { "Yes" } else { "No" });
}
39 changes: 39 additions & 0 deletions atcoder/abc327/b.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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 b: i64 = get();
for a in 1..19 {
let mut x: i64 = a;
for _ in 1..a {
x = x.saturating_mul(a);
}
if x == b {
println!("{}", a);
return;
}
}
println!("-1");
}
65 changes: 65 additions & 0 deletions atcoder/abc327/c.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// 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 ; $len:expr ]) => {
(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
};
($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
input!(a: [[usize; 9]; 9]);
for i in 0..9 {
let mut s = 0;
for j in 0..9 {
s |= 1 << a[i][j];
}
if s != 0x3fe {
println!("No");
return;
}
}
for i in 0..9 {
let mut s = 0;
for j in 0..9 {
s |= 1 << a[j][i];
}
if s != 0x3fe {
println!("No");
return;
}
}
for i in 0..9 {
let mut s = 0;
for j in 0..9 {
s |= 1 << a[(i / 3) * 3 + j / 3][(i % 3) * 3 + j % 3];
}
if s != 0x3fe {
println!("No");
return;
}
}
println!("Yes");
}
68 changes: 68 additions & 0 deletions atcoder/abc327/d.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// 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 ; $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"));
}

fn dfs(v: usize, g: &[Vec<usize>], vis: &mut Vec<i32>, c: i32) -> Result<(), ()> {
if vis[v] != 0 {
if vis[v] != c {
return Err(());
}
return Ok(());
}
vis[v] = c;
for &to in &g[v] {
dfs(to, g, vis, -c)?;
}
Ok(())
}

fn main() {
input! {
n: usize, m: usize,
a: [usize1; m],
b: [usize1; m],
}
let mut g = vec![vec![]; n];
for i in 0..m {
g[a[i]].push(b[i]);
g[b[i]].push(a[i]);
}
let mut vis = vec![0; n];
for i in 0..n {
if vis[i] == 0 {
if dfs(i, &g, &mut vis, 1).is_err() {
println!("No");
return;
};
}
}
println!("Yes");
}
57 changes: 57 additions & 0 deletions atcoder/abc327/e.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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 ; $len:expr ]) => {
(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
};
($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
input! {
n: usize,
p: [f64; n],
}
let mut sum = vec![0.0; n + 1];
for i in 0..n {
sum[i + 1] = sum[i] * 0.9 + 1.0;
}
const INF: f64 = 1.0 / 0.0;
let mut dp = vec![-INF; n + 1];
dp[0] = 0.0;
for p in p {
let mut ep = dp.clone();
for i in 0..n {
let val = (sum[i] * 0.9 * dp[i] + p) / sum[i + 1];
ep[i + 1] = ep[i + 1].max(val);
}
dp = ep;
}
let mut ans = -10000.0f64;
for i in 1..n + 1 {
ans = ans.max(dp[i] - 1200.0 / (i as f64).sqrt());
}
println!("{}", ans);
}
2 changes: 2 additions & 0 deletions atcoder/abc327/remain.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
f
g
38 changes: 38 additions & 0 deletions atcoder/abc330/a.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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 ; $len:expr ]) => {
(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
};
($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
input! {
n: usize, l: i64,
a: [i64; n],
}
println!("{}", a.iter().filter(|&&x| x >= l).count());
}
45 changes: 45 additions & 0 deletions atcoder/abc330/b.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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 ; $len:expr ]) => {
(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
};
($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
input! {
n: usize, l: i64, r: i64,
a: [i64; n],
}
for mut a in a {
if a < l {
a = l;
} else if a > r {
a = r;
}
print!("{} ", a);
}
}
60 changes: 60 additions & 0 deletions atcoder/abc330/c.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use std::cmp::*;
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 nth(a: i64, n: i64) -> i64 {
let mut pass = 0;
let mut fail = std::cmp::min(a, 1 << ((60 + n - 1) / n)) + 1;
while fail - pass > 1 {
let mid = (fail + pass) / 2;
let mut tmp = 1i64;
for _ in 0..n {
tmp = tmp.saturating_mul(mid);
}
if tmp <= a {
pass = mid;
} else {
fail = mid;
}
}
pass
}

fn main() {
let d: i64 = get();
let mut ans = d;
for i in 0..1_500_000 {
if i * i > d {
continue;
}
let r = d - i * i;
let s = nth(r, 2);
for j in 0..2 {
let s = s + j;
ans = min(ans, (i * i + s * s - d).abs());
}
}
println!("{}", ans);
}
Loading

0 comments on commit aad9422

Please sign in to comment.