complete 2022.rs 1264.rs 1318.rs 3731.rs 4633.rs 7140.rs 7541.rs 14315.rs 17204.rs 25208.rs
This commit is contained in:
56
storage/zeta/rs/completed/1022.rs
Normal file
56
storage/zeta/rs/completed/1022.rs
Normal file
@@ -0,0 +1,56 @@
|
||||
use std::{cmp::max, io::stdin};
|
||||
|
||||
fn get_value(r: i32, c: i32) -> i32 {
|
||||
let d = max(r.abs(), c.abs());
|
||||
|
||||
if d == 0 {
|
||||
return 1;
|
||||
}
|
||||
|
||||
let prev_max = (2 * d - 1) * (2 * d - 1);
|
||||
|
||||
if c == d && r < d {
|
||||
prev_max + (d - r)
|
||||
} else if r == -d {
|
||||
prev_max + 2 * d + (d - c)
|
||||
} else if c == -d {
|
||||
prev_max + 4 * d + (r + d)
|
||||
} else {
|
||||
prev_max + 6 * d + c + d
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut line = String::new();
|
||||
stdin().read_line(&mut line).unwrap();
|
||||
let mut iter = line
|
||||
.split_ascii_whitespace()
|
||||
.map(|x| x.parse::<i32>().unwrap());
|
||||
|
||||
let (r1, c1, r2, c2) = (
|
||||
iter.next().unwrap(),
|
||||
iter.next().unwrap(),
|
||||
iter.next().unwrap(),
|
||||
iter.next().unwrap(),
|
||||
);
|
||||
|
||||
let mut spiral = vec![vec![0; (c2 - c1 + 1) as usize]; (r2 - r1 + 1) as usize];
|
||||
let mut max_v = 0;
|
||||
for i in r1..=r2 {
|
||||
for j in c1..=c2 {
|
||||
let v = get_value(i, j);
|
||||
max_v = max(max_v, v);
|
||||
spiral[(i - r1) as usize][(j - c1) as usize] = v;
|
||||
}
|
||||
}
|
||||
|
||||
let offset = max_v.to_string().len();
|
||||
|
||||
for i in 0..(r2 - r1 + 1) as usize {
|
||||
for j in 0..(c2 - c1) as usize {
|
||||
print!("{:width$} ", spiral[i][j], width = offset);
|
||||
}
|
||||
print!("{:width$}", spiral[i][(c2 - c1) as usize], width = offset);
|
||||
println!();
|
||||
}
|
||||
}
|
||||
25
storage/zeta/rs/completed/1264.rs
Normal file
25
storage/zeta/rs/completed/1264.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use std::io::stdin;
|
||||
|
||||
fn main() {
|
||||
let mut line = String::new();
|
||||
|
||||
loop {
|
||||
line.clear();
|
||||
stdin().read_line(&mut line).unwrap();
|
||||
|
||||
let s = line.chars().collect::<Vec<char>>();
|
||||
if s[0] == '#' {
|
||||
break;
|
||||
}
|
||||
let cnt = s
|
||||
.iter()
|
||||
.map(|x| x.to_ascii_lowercase())
|
||||
.filter(|x| match x {
|
||||
'a' | 'e' | 'i' | 'o' | 'u' => true,
|
||||
_ => false,
|
||||
})
|
||||
.count();
|
||||
|
||||
println!("{}", cnt);
|
||||
}
|
||||
}
|
||||
39
storage/zeta/rs/completed/1318.rs
Normal file
39
storage/zeta/rs/completed/1318.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
const PKR_RANKS: [u64; 12] = [
|
||||
6_612_900, // TOP
|
||||
9_730_740, // ONE_PAIR
|
||||
2_532_816, // TWO_PAIR
|
||||
0_732_160, // TRIPLE
|
||||
0_282_060, // ST
|
||||
0_039_780, // BST
|
||||
0_039_780, // MT
|
||||
0_205_976, // F
|
||||
0_165_984, // FH
|
||||
0_014_664, // FC
|
||||
0_001_472, // SF
|
||||
0_000_188, // RSF
|
||||
];
|
||||
|
||||
const PKR_TOT: u64 = {
|
||||
let mut s = 0;
|
||||
let mut i = 0;
|
||||
while i < PKR_RANKS.len() {
|
||||
s += PKR_RANKS[i];
|
||||
i += 1;
|
||||
}
|
||||
s
|
||||
};
|
||||
|
||||
fn gcd(a: u64, b: u64) -> u64 {
|
||||
if b == 0 {
|
||||
a
|
||||
} else {
|
||||
gcd(b, a % b)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
for &cnt in PKR_RANKS.iter() {
|
||||
let g = gcd(PKR_TOT, cnt);
|
||||
println!("{}/{}", cnt / g, PKR_TOT / g);
|
||||
}
|
||||
}
|
||||
1
storage/zeta/rs/completed/14315.rs
Normal file
1
storage/zeta/rs/completed/14315.rs
Normal file
@@ -0,0 +1 @@
|
||||
fn main(){let s=std::io::read_to_string(std::io::stdin()).unwrap();let mut i=s.split_whitespace().flat_map(str::parse::<u64>);for j in 1..=i.next().unwrap(){let p=i.next().unwrap().min(i.next().unwrap());println!("Case #{j}: {}",p*p+p>>1)}}
|
||||
45
storage/zeta/rs/completed/17204.rs
Normal file
45
storage/zeta/rs/completed/17204.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
use std::io::{read_to_string, stdin};
|
||||
|
||||
fn main() {
|
||||
let temp = read_to_string(stdin()).unwrap();
|
||||
let mut iter = temp
|
||||
.split_ascii_whitespace()
|
||||
.map(|x| x.parse::<usize>().unwrap());
|
||||
let (n, k) = (iter.next().unwrap(), iter.next().unwrap());
|
||||
|
||||
let mut edges = vec![0; n];
|
||||
let mut flg = false;
|
||||
(0..n).for_each(|i| {
|
||||
let nxt = iter.next().unwrap();
|
||||
edges[i] = nxt;
|
||||
if nxt == k {
|
||||
flg = true;
|
||||
}
|
||||
});
|
||||
|
||||
if !flg {
|
||||
println!("{}", -1);
|
||||
return;
|
||||
}
|
||||
|
||||
let mut curr = 0;
|
||||
let mut nxt;
|
||||
let mut vis = vec![false; n];
|
||||
let mut m = 0;
|
||||
'a: loop {
|
||||
if vis[curr] {
|
||||
m = -1;
|
||||
break;
|
||||
} else {
|
||||
vis[curr] = true;
|
||||
}
|
||||
if curr == k {
|
||||
break 'a;
|
||||
}
|
||||
nxt = edges[curr];
|
||||
|
||||
curr = nxt;
|
||||
m += 1;
|
||||
}
|
||||
println!("{}", m);
|
||||
}
|
||||
217
storage/zeta/rs/completed/25208.rs
Normal file
217
storage/zeta/rs/completed/25208.rs
Normal file
@@ -0,0 +1,217 @@
|
||||
use std::{cmp::min, collections::VecDeque, io::stdin};
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub enum Cell {
|
||||
Empty,
|
||||
Wall,
|
||||
Detective,
|
||||
Robber,
|
||||
}
|
||||
|
||||
impl Cell {
|
||||
fn from_char(c: char) -> Self {
|
||||
match c {
|
||||
'#' => Cell::Wall,
|
||||
'.' => Cell::Empty,
|
||||
'D' => Cell::Detective,
|
||||
'R' => Cell::Robber,
|
||||
_ => Cell::Empty,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub enum JailState {
|
||||
OpenBelow,
|
||||
OpenNorth,
|
||||
OpenSouth,
|
||||
OpenWest,
|
||||
OpenEast,
|
||||
OpenAbove,
|
||||
}
|
||||
|
||||
impl JailState {
|
||||
pub fn to_index(&self) -> usize {
|
||||
match self {
|
||||
Self::OpenBelow => 0,
|
||||
Self::OpenNorth => 1,
|
||||
Self::OpenSouth => 2,
|
||||
Self::OpenWest => 3,
|
||||
Self::OpenEast => 4,
|
||||
Self::OpenAbove => 5,
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum Direction {
|
||||
North,
|
||||
West,
|
||||
East,
|
||||
South,
|
||||
}
|
||||
|
||||
impl Direction {
|
||||
pub fn value(&self) -> (isize, isize) {
|
||||
match self {
|
||||
Self::North => (-1, 0),
|
||||
Self::West => (0, -1),
|
||||
Self::East => (0, 1),
|
||||
Self::South => (1, 0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Jail {
|
||||
state: JailState,
|
||||
pos: (usize, usize),
|
||||
}
|
||||
|
||||
impl Jail {
|
||||
pub fn roll(&self, dir: Direction) -> Self {
|
||||
let next_pos = (
|
||||
(self.pos.0 as isize + dir.value().0) as usize,
|
||||
(self.pos.1 as isize + dir.value().1) as usize,
|
||||
);
|
||||
let next_state = match self.state {
|
||||
JailState::OpenBelow => match dir {
|
||||
Direction::East => JailState::OpenWest,
|
||||
Direction::North => JailState::OpenSouth,
|
||||
Direction::South => JailState::OpenNorth,
|
||||
Direction::West => JailState::OpenEast,
|
||||
},
|
||||
JailState::OpenAbove => match dir {
|
||||
Direction::East => JailState::OpenEast,
|
||||
Direction::North => JailState::OpenNorth,
|
||||
Direction::South => JailState::OpenSouth,
|
||||
Direction::West => JailState::OpenWest,
|
||||
},
|
||||
JailState::OpenEast => match dir {
|
||||
Direction::East => JailState::OpenBelow,
|
||||
Direction::West => JailState::OpenAbove,
|
||||
Direction::North | Direction::South => JailState::OpenEast,
|
||||
},
|
||||
JailState::OpenNorth => match dir {
|
||||
Direction::North => JailState::OpenBelow,
|
||||
Direction::South => JailState::OpenAbove,
|
||||
Direction::East | Direction::West => JailState::OpenNorth,
|
||||
},
|
||||
JailState::OpenSouth => match dir {
|
||||
Direction::South => JailState::OpenBelow,
|
||||
Direction::North => JailState::OpenAbove,
|
||||
Direction::East | Direction::West => JailState::OpenSouth,
|
||||
},
|
||||
JailState::OpenWest => match dir {
|
||||
Direction::West => JailState::OpenBelow,
|
||||
Direction::East => JailState::OpenAbove,
|
||||
_ => JailState::OpenWest,
|
||||
},
|
||||
};
|
||||
Self {
|
||||
state: next_state,
|
||||
pos: next_pos,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn find_minimum_rolls_to_catch_robber(n: usize, m: usize, field: &Vec<Vec<Cell>>) -> isize {
|
||||
let (d_pos, r_pos) = {
|
||||
let mut d = (0, 0);
|
||||
let mut r = (0, 0);
|
||||
for i in 0..n {
|
||||
for j in 0..m {
|
||||
if field[i][j] == Cell::Detective {
|
||||
d = (i, j);
|
||||
} else if field[i][j] == Cell::Robber {
|
||||
r = (i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
(d, r)
|
||||
};
|
||||
|
||||
let mut deq: VecDeque<(usize, Jail)> = VecDeque::new();
|
||||
let mut vis: Vec<Vec<Vec<bool>>> = vec![vec![vec![false; 6]; m]; n];
|
||||
deq.push_back((
|
||||
0,
|
||||
Jail {
|
||||
state: JailState::OpenBelow,
|
||||
pos: d_pos,
|
||||
},
|
||||
));
|
||||
|
||||
let mut minima = usize::MAX;
|
||||
while !deq.is_empty() {
|
||||
let (step, jail) = deq.pop_front().unwrap();
|
||||
let pos = jail.pos;
|
||||
|
||||
if field[pos.0][pos.1] == Cell::Robber {
|
||||
if jail.state == JailState::OpenBelow {
|
||||
minima = min(minima, step);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if vis[pos.0][pos.1][jail.state.to_index()] {
|
||||
continue;
|
||||
} else {
|
||||
vis[pos.0][pos.1][jail.state.to_index()] = true;
|
||||
}
|
||||
|
||||
for dir in [
|
||||
Direction::North,
|
||||
Direction::South,
|
||||
Direction::East,
|
||||
Direction::West,
|
||||
] {
|
||||
let next_pos = (
|
||||
(pos.0 as isize + dir.value().0),
|
||||
(pos.1 as isize + dir.value().1),
|
||||
);
|
||||
|
||||
if next_pos.0 < 0 || next_pos.1 < 0 {
|
||||
continue;
|
||||
}
|
||||
if next_pos.0 >= n as isize || next_pos.1 >= m as isize {
|
||||
continue;
|
||||
}
|
||||
if field[next_pos.0 as usize][next_pos.1 as usize] == Cell::Wall {
|
||||
continue;
|
||||
}
|
||||
|
||||
let next_jail = jail.roll(dir);
|
||||
deq.push_back((step + 1, next_jail));
|
||||
}
|
||||
}
|
||||
|
||||
if minima == usize::MAX {
|
||||
-1
|
||||
} else {
|
||||
minima as isize
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut line = String::new();
|
||||
stdin().read_line(&mut line).unwrap();
|
||||
let mut iter = line
|
||||
.trim()
|
||||
.split_ascii_whitespace()
|
||||
.map(|x| x.parse::<usize>().unwrap());
|
||||
let (n, m) = (iter.next().unwrap(), iter.next().unwrap());
|
||||
|
||||
let field = (0..n)
|
||||
.map(|_| {
|
||||
line.clear();
|
||||
stdin().read_line(&mut line).unwrap();
|
||||
line.trim()
|
||||
.chars()
|
||||
.map(|c| Cell::from_char(c))
|
||||
.collect::<Vec<Cell>>()
|
||||
})
|
||||
.collect::<Vec<Vec<Cell>>>();
|
||||
|
||||
let res = find_minimum_rolls_to_catch_robber(n, m, &field);
|
||||
|
||||
println!("{}", res);
|
||||
}
|
||||
102
storage/zeta/rs/completed/3731.rs
Normal file
102
storage/zeta/rs/completed/3731.rs
Normal file
@@ -0,0 +1,102 @@
|
||||
use std::io::{read_to_string, stdin};
|
||||
|
||||
fn is_win(
|
||||
vis: &mut Vec<Vec<usize>>,
|
||||
rcum: &Vec<Vec<usize>>,
|
||||
ccum: &Vec<Vec<usize>>,
|
||||
curr: (usize, usize),
|
||||
) -> bool {
|
||||
if vis[curr.0][curr.1] != usize::MAX {
|
||||
return vis[curr.0][curr.1] == 1;
|
||||
}
|
||||
|
||||
let r = rcum[curr.0][curr.1];
|
||||
let c = ccum[curr.0][curr.1];
|
||||
|
||||
if curr.0 == 0 && curr.1 == 0 {
|
||||
let t = r % 2 == 0;
|
||||
vis[curr.0][curr.1] = t as usize;
|
||||
return t;
|
||||
} else if curr.0 == 0 {
|
||||
let t = if c % 2 == 0 {
|
||||
r % 2 == 0 || !is_win(vis, rcum, ccum, (curr.0, curr.1 - 1))
|
||||
} else {
|
||||
r % 2 == 0
|
||||
};
|
||||
vis[curr.0][curr.1] = t as usize;
|
||||
return t;
|
||||
} else if curr.1 == 0 {
|
||||
let t = if r % 2 == 0 {
|
||||
c % 2 == 0 || !is_win(vis, rcum, ccum, (curr.0 - 1, curr.1))
|
||||
} else {
|
||||
c % 2 == 0
|
||||
};
|
||||
vis[curr.0][curr.1] = t as usize;
|
||||
return t;
|
||||
}
|
||||
|
||||
if r % 2 == 0 && c % 2 == 0 {
|
||||
let t = !is_win(vis, rcum, ccum, (curr.0 - 1, curr.1))
|
||||
|| !is_win(vis, rcum, ccum, (curr.0, curr.1 - 1));
|
||||
vis[curr.0][curr.1] = t as usize;
|
||||
t
|
||||
} else if c % 2 == 0 {
|
||||
let t = !is_win(vis, rcum, ccum, (curr.0, curr.1 - 1));
|
||||
vis[curr.0][curr.1] = t as usize;
|
||||
t
|
||||
} else if r % 2 == 0 {
|
||||
let t = !is_win(vis, rcum, ccum, (curr.0 - 1, curr.1));
|
||||
vis[curr.0][curr.1] = t as usize;
|
||||
t
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let temp = read_to_string(stdin()).unwrap();
|
||||
let mut iter = temp
|
||||
.split_ascii_whitespace()
|
||||
.map(|x| x.parse::<usize>().unwrap());
|
||||
loop {
|
||||
let n = match iter.next() {
|
||||
Some(x) => x,
|
||||
None => {
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
let mat = {
|
||||
let mut mat = vec![vec![0; n]; n];
|
||||
for i in 0..n {
|
||||
for j in 0..n {
|
||||
mat[i][j] = iter.next().unwrap();
|
||||
}
|
||||
}
|
||||
mat
|
||||
};
|
||||
let (rcum, ccum) = {
|
||||
let mut rcum = vec![vec![0; n]; n];
|
||||
let mut ccum = vec![vec![0; n]; n];
|
||||
|
||||
for i in 0..n {
|
||||
rcum[i][0] = mat[i][0];
|
||||
ccum[0][i] = mat[0][i];
|
||||
for j in 1..n {
|
||||
rcum[i][j] = rcum[i][j - 1] + mat[i][j];
|
||||
ccum[j][i] = ccum[j - 1][i] + mat[j][i];
|
||||
}
|
||||
}
|
||||
|
||||
(rcum, ccum)
|
||||
};
|
||||
|
||||
let mut vis = vec![vec![usize::MAX; n]; n];
|
||||
|
||||
if is_win(&mut vis, &rcum, &ccum, (n - 1, n - 1)) {
|
||||
println!("W");
|
||||
} else {
|
||||
println!("L");
|
||||
}
|
||||
}
|
||||
}
|
||||
55
storage/zeta/rs/completed/4633.rs
Normal file
55
storage/zeta/rs/completed/4633.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
use std::io::{read_to_string, stdin};
|
||||
|
||||
fn decrypt(x: u64, s: Vec<char>, p: Vec<char>, c: Vec<char>) -> Vec<char> {
|
||||
let size = s.len();
|
||||
let n = c.len();
|
||||
let mut m: Vec<char> = vec!['*'; n];
|
||||
|
||||
let d = ((n as f64).powf(1.5) as u64 + x) as usize % n;
|
||||
for i in 0..size {
|
||||
if s[i] == c[d] {
|
||||
m[d] = p[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
for i in 0..n - 1 {
|
||||
let mut pp = 0;
|
||||
let mut ps = 0;
|
||||
let j = (d + n - i - 1) % n;
|
||||
let j_nxt = (d + n - i) % n;
|
||||
for jj in 0..size {
|
||||
if m[j_nxt] == s[jj] {
|
||||
ps = jj;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for jj in 0..size {
|
||||
if c[j] == s[jj] {
|
||||
pp = jj;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m[j] = p[pp ^ ps];
|
||||
}
|
||||
|
||||
m
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let temp = read_to_string(stdin()).unwrap();
|
||||
let mut iter = temp.split_ascii_whitespace();
|
||||
|
||||
loop {
|
||||
let x = iter.next().unwrap().parse::<u64>().unwrap();
|
||||
if x == 0 {
|
||||
break;
|
||||
}
|
||||
|
||||
let s = iter.next().unwrap().chars().collect();
|
||||
let p = iter.next().unwrap().chars().collect();
|
||||
let c = iter.next().unwrap().chars().collect();
|
||||
let msg = decrypt(x, s, p, c);
|
||||
println!("{}", msg.iter().collect::<String>());
|
||||
}
|
||||
}
|
||||
11
storage/zeta/rs/completed/7140.rs
Normal file
11
storage/zeta/rs/completed/7140.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
fn main() {
|
||||
let v = 103;
|
||||
println!("{}", v);
|
||||
for i in 0..v {
|
||||
println!("{}", 0);
|
||||
}
|
||||
|
||||
let q = 1;
|
||||
println!("{}", q);
|
||||
println!("{} {}", 0, 1);
|
||||
}
|
||||
54
storage/zeta/rs/completed/7541.rs
Normal file
54
storage/zeta/rs/completed/7541.rs
Normal file
@@ -0,0 +1,54 @@
|
||||
use std::{io::stdin, u8};
|
||||
|
||||
fn main() {
|
||||
let mut line = String::new();
|
||||
stdin().read_line(&mut line).unwrap();
|
||||
let n = line.trim().parse::<usize>().unwrap();
|
||||
|
||||
(1..=n).for_each(|case| {
|
||||
line.clear();
|
||||
stdin().read_line(&mut line).unwrap();
|
||||
|
||||
let mut id = line
|
||||
.trim()
|
||||
.chars()
|
||||
.map(|x| match x {
|
||||
'?' => u8::MAX,
|
||||
_ => x as u8 - '0' as u8,
|
||||
})
|
||||
.collect::<Vec<u8>>();
|
||||
|
||||
let mut idx = 0;
|
||||
let mut k: u64 = 0;
|
||||
let len = id.len();
|
||||
let r_s: u64 = id
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, &x)| {
|
||||
if x == u8::MAX {
|
||||
idx = i;
|
||||
k = [9, 3, 7][(len - i - 1) % 3];
|
||||
0
|
||||
} else {
|
||||
let t = x as u64 * [9, 3, 7][(len - i - 1) % 3] as u64;
|
||||
t
|
||||
}
|
||||
})
|
||||
.sum();
|
||||
let mut x = 0;
|
||||
for i in 0..10 {
|
||||
if (i * k + r_s) % 10 == 0 {
|
||||
x = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
id[idx] = x as u8;
|
||||
println!(
|
||||
"Scenario #{}:\n{}\n",
|
||||
case,
|
||||
id.iter()
|
||||
.map(|&x| ('0' as u8 + x as u8) as char)
|
||||
.collect::<String>()
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user