-
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/abc349/a.rs atcoder/abc349/b.rs atcoder/abc349/c.rs atcod…
…er/abc349/d.rs atcoder/abc349/e.rs atcoder/abc349/f.rs atcoder/abc349/g.rs
- Loading branch information
Showing
7 changed files
with
588 additions
and
0 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 n: i32 = get(); | ||
let mut x = 0; | ||
for _ in 1..n { | ||
let y: i32 = get(); | ||
x -= y; | ||
} | ||
println!("{}", x) | ||
} |
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,17 @@ | ||
fn getline() -> String { | ||
let mut ret = String::new(); | ||
std::io::stdin().read_line(&mut ret).ok().unwrap(); | ||
ret | ||
} | ||
|
||
fn main() { | ||
let mut f = [0; 26]; | ||
for c in getline().trim().bytes() { | ||
f[(c - b'a') as usize] += 1; | ||
} | ||
let mut g = vec![0; 101]; | ||
for i in 0..26 { | ||
g[f[i] as usize] += 1; | ||
} | ||
println!("{}", if g[1..].iter().all(|&x| x == 0 || x == 2) { "Yes" } else { "No" }); | ||
} |
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,21 @@ | ||
fn getline() -> String { | ||
let mut ret = String::new(); | ||
std::io::stdin().read_line(&mut ret).ok().unwrap(); | ||
ret | ||
} | ||
|
||
fn main() { | ||
let mut s: Vec<_> = getline().trim().bytes().collect(); | ||
let t: Vec<_> = getline().trim().bytes().collect(); | ||
s.push(b'x'); | ||
let mut i = 0; | ||
for c in s { | ||
if i >= 3 { | ||
break; | ||
} | ||
if t[i] == c + b'A' - b'a' { | ||
i += 1; | ||
} | ||
} | ||
println!("{}", if i >= 3 { "Yes" } else { "No" }); | ||
} |
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,43 @@ | ||
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 l: i64 = get(); | ||
let r: i64 = get(); | ||
let mut ans = vec![]; | ||
while l < r { | ||
let mut i = 0; | ||
while l + (1 << i) <= r && l % (1 << i) == 0 { | ||
i += 1; | ||
} | ||
i -= 1; | ||
ans.push((l, l + (1 << i))); | ||
l += 1 << i; | ||
} | ||
println!("{}", ans.len()); | ||
for (l, r) in ans { | ||
println!("{} {}", l, r); | ||
} | ||
} |
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,80 @@ | ||
// 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 dfs(a: &[Vec<i64>], b: [[i8; 3]; 3]) -> bool { | ||
// 3 in a row? | ||
for i in 0..3 { | ||
if b[i].iter().all(|&b| b == -1) { | ||
return false; | ||
} | ||
if (0..3).all(|j| b[j][i] == -1) { | ||
return false; | ||
} | ||
} | ||
if (0..3).all(|j| b[j][j] == -1) { | ||
return false; | ||
} | ||
if (0..3).all(|j| b[j][2 - j] == -1) { | ||
return false; | ||
} | ||
if b.iter().all(|b| b.iter().all(|&b| b != 0)) { | ||
// check | ||
let mut sum = 0; | ||
for i in 0..3 { | ||
for j in 0..3 { | ||
sum += a[i][j] * b[i][j] as i64; | ||
} | ||
} | ||
return sum > 0; | ||
} | ||
let mut win = false; | ||
for i in 0..3 { | ||
for j in 0..3 { | ||
if b[i][j] != 0 { continue; } | ||
let mut newb = b; | ||
for x in 0..9 { | ||
newb[x / 3][x % 3] *= -1; | ||
} | ||
newb[i][j] = -1; | ||
if !dfs(a, newb) { | ||
win = true; | ||
} | ||
} | ||
} | ||
win | ||
} | ||
|
||
fn main() { | ||
input!(a: [[i64; 3]; 3]); | ||
let b = [[0; 3]; 3]; | ||
let res = dfs(&a, b); | ||
println!("{}", if res { "Takahashi" } else { "Aoki" }); | ||
} |
Oops, something went wrong.