Skip to content

Commit 5b68983

Browse files
committed
Use proconio in most of the examples
1 parent 5340eed commit 5b68983

14 files changed

+130
-249
lines changed

examples/abc054-c.rs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,15 @@
22

33
use itertools::Itertools as _;
44
use petgraph::graph::UnGraph;
5-
6-
use std::io::{self, Read};
5+
use proconio::input;
6+
use proconio::marker::Usize1;
77

88
fn main() {
9-
let mut input = read_to_static(io::stdin()).split_whitespace();
10-
macro_rules! read {
11-
([$tt:tt]) => (read!([$tt; read!(usize)]));
12-
([$tt:tt; $n:expr]) => ((0..$n).map(|_| read!($tt)).collect::<Vec<_>>());
13-
(($($tt:tt),+)) => (($(read!($tt)),*));
14-
($ty:ty) => (input.next().unwrap().parse::<$ty>().unwrap());
15-
({ Usize1 }) => {
16-
read!(usize) - 1
17-
};
9+
input! {
10+
n: usize,
11+
abs: [(Usize1, Usize1)],
1812
}
1913

20-
let n = read!(usize);
21-
let abs = read!([({ Usize1 }, { Usize1 })]);
22-
2314
let graph = UnGraph::<(), (), usize>::from_edges(abs);
2415
let ans = graph
2516
.node_indices()
@@ -28,9 +19,3 @@ fn main() {
2819
.count();
2920
println!("{}", ans);
3021
}
31-
32-
fn read_to_static(mut source: impl Read) -> &'static str {
33-
let mut input = "".to_owned();
34-
source.read_to_string(&mut input).unwrap();
35-
Box::leak(input.into_boxed_str())
36-
}

examples/abc073-d.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
// https://atcoder.jp/contests/abc073/tasks/abc073_d
22

33
use itertools::Itertools as _;
4-
use petgraph::graph::{NodeIndex, UnGraph};
4+
use num::traits::One;
5+
use petgraph::graph::{IndexType, NodeIndex, UnGraph};
6+
use proconio::input;
7+
use proconio::source::{Readable, Source};
58

69
use std::collections::HashMap;
7-
use std::io::{self, Read};
10+
use std::io::BufRead;
11+
use std::marker::PhantomData;
12+
use std::ops::Sub;
813

914
fn main() {
10-
let mut input = read_to_static(io::stdin()).split_whitespace();
11-
macro_rules! read {
12-
([$tt:tt]) => (read!([$tt; read!(usize)]));
13-
([$tt:tt; $n:expr]) => ((0..$n).map(|_| read!($tt)).collect::<Vec<_>>());
14-
(($($tt:tt),+)) => (($(read!($tt)),*));
15-
($ty:ty) => (input.next().unwrap().parse::<$ty>().unwrap());
16-
({ NodeIndex1 }) => {
17-
NodeIndex::from(read!(u32) - 1)
18-
};
15+
input! {
16+
_n: usize,
17+
m: usize,
18+
r: usize,
19+
rs: [NodeIndex1<u32>; r],
20+
abcs: [(NodeIndex1<u32>, NodeIndex1<u32>, u32); m],
1921
}
2022

21-
let (_, m, r) = read!((usize, usize, usize));
22-
let rs = read!([{ NodeIndex1 }; r]);
23-
let abcs = read!([({ NodeIndex1 }, { NodeIndex1 }, u32); m]);
24-
2523
let graph = UnGraph::<(), u32>::from_edges(abcs);
2624

2725
let dijkstra = rs
@@ -41,8 +39,12 @@ fn main() {
4139
println!("{}", ans);
4240
}
4341

44-
fn read_to_static(mut source: impl Read) -> &'static str {
45-
let mut input = "".to_owned();
46-
source.read_to_string(&mut input).unwrap();
47-
Box::leak(input.into_boxed_str())
42+
struct NodeIndex1<Ix>(PhantomData<fn() -> Ix>);
43+
44+
impl<Ix: IndexType + Readable<Output = Ix> + One + Sub<Output = Ix>> Readable for NodeIndex1<Ix> {
45+
type Output = NodeIndex<Ix>;
46+
47+
fn read<R: BufRead, S: Source<R>>(source: &mut S) -> NodeIndex<Ix> {
48+
NodeIndex::from(Ix::read(source) - Ix::one())
49+
}
4850
}

examples/abc129-f.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@
33
use ndarray::{array, Array2, LinalgScalar};
44
use num::{PrimInt, Unsigned};
55
use num_derive::{One, Zero};
6+
use proconio::input;
7+
use proconio::source::{Readable, Source};
68

79
use std::cell::Cell;
8-
use std::io::{self, Read};
10+
use std::io::BufRead;
911
use std::ops::{Add, Div, Mul, Sub};
1012
use std::{cmp, fmt};
1113

1214
fn main() {
13-
let mut input = read_to_static(io::stdin()).split_whitespace();
14-
macro_rules! read(() => (input.next().unwrap().parse().unwrap()));
15-
16-
let (l, a, b, m): (u64, u64, u64, u64) = (read!(), read!(), read!(), read!());
17-
18-
MOD.with(|cell| cell.set(m));
15+
input! {
16+
l: u64,
17+
a: u64,
18+
b: u64,
19+
_m: Mod,
20+
}
1921

2022
let count = |d| -> _ {
2123
let count =
@@ -58,6 +60,16 @@ thread_local! {
5860
static MOD: Cell<u64> = Cell::new(0);
5961
}
6062

63+
enum Mod {}
64+
65+
impl Readable for Mod {
66+
type Output = ();
67+
68+
fn read<R: BufRead, S: Source<R>>(source: &mut S) {
69+
MOD.with(|cell| cell.set(u64::read(source)));
70+
}
71+
}
72+
6173
#[derive(Zero, One, Debug, Clone, Copy)]
6274
struct Z(u64);
6375

@@ -104,9 +116,3 @@ impl Div for Z {
104116
unreachable!("should not be performed")
105117
}
106118
}
107-
108-
fn read_to_static(mut source: impl Read) -> &'static str {
109-
let mut input = "".to_owned();
110-
source.read_to_string(&mut input).unwrap();
111-
Box::leak(input.into_boxed_str())
112-
}

examples/abc142-c.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
11
// https://atcoder.jp/contests/abc142/tasks/abc142_c
22

33
use itertools::Itertools as _;
4+
use proconio::input;
5+
use proconio::marker::Isize1;
46
use superslice::Ext2 as _;
57

6-
use std::io::{self, Read};
7-
88
fn main() {
9-
let mut input = read_to_static(io::stdin()).split_whitespace();
10-
macro_rules! read {
11-
([$tt:tt]) => (read!([$tt; read!(usize)]));
12-
([$tt:tt; $n:expr]) => ((0..$n).map(|_| read!($tt)).collect::<Vec<_>>());
13-
(($($tt:tt),+)) => (($(read!($tt)),*));
14-
($ty:ty) => (input.next().unwrap().parse::<$ty>().unwrap());
15-
({ Isize1 }) => {
16-
read!(isize) - 1
17-
};
9+
input! {
10+
mut a: [Isize1],
1811
}
1912

20-
let mut a = read!([{ Isize1 }]);
2113
a.invert_permutation();
2214
println!("{}", a.iter().map(|a| a + 1).format(" "));
2315
}
24-
25-
fn read_to_static(mut source: impl Read) -> &'static str {
26-
let mut input = "".to_owned();
27-
source.read_to_string(&mut input).unwrap();
28-
Box::leak(input.into_boxed_str())
29-
}

examples/abc144-d.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// https://atcoder.jp/contests/abc144/tasks/abc144_d
22

3+
use proconio::input;
4+
35
use std::f64::consts::PI;
4-
use std::io::{self, Read};
56

67
fn main() {
7-
let mut input = read_to_static(io::stdin()).split_whitespace();
8-
macro_rules! read(() => (input.next().unwrap().parse().unwrap()));
9-
10-
let (a, b, x): (f64, f64, f64) = (read!(), read!(), read!());
8+
input! {
9+
a: f64,
10+
b: f64,
11+
x: f64,
12+
}
1113

1214
let ans = 180.0 / PI
1315
* if x >= (a.powi(2) * b) / 2.0 {
@@ -17,9 +19,3 @@ fn main() {
1719
};
1820
println!("{}", ans);
1921
}
20-
21-
fn read_to_static(mut source: impl Read) -> &'static str {
22-
let mut input = "".to_owned();
23-
source.read_to_string(&mut input).unwrap();
24-
Box::leak(input.into_boxed_str())
25-
}

examples/abc150-d.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
// https://atcoder.jp/contests/abc150/tasks/abc150_d
22

33
use itertools::Itertools as _;
4-
5-
use std::io::{self, Read};
4+
use proconio::input;
65

76
fn main() {
8-
let mut input = read_to_static(io::stdin()).split_whitespace();
9-
macro_rules! read {
10-
([$tt:tt]) => (read!([$tt; read!(usize)]));
11-
([$tt:tt; $n:expr]) => ((0..$n).map(|_| read!($tt)).collect::<Vec<_>>());
12-
(($($tt:tt),+)) => (($(read!($tt)),*));
13-
($ty:ty) => (input.next().unwrap().parse::<$ty>().unwrap());
7+
input! {
8+
n: usize,
9+
m: usize,
10+
a: [usize; n],
1411
}
1512

16-
let (n, m) = read!((usize, usize));
17-
let a = read!([usize; n]);
18-
1913
if !a.iter().copied().map(usize::trailing_zeros).all_equal() {
2014
println!("0");
2115
return;
@@ -25,9 +19,3 @@ fn main() {
2519
let ans = (m + x0) / (2 * x0);
2620
println!("{}", ans);
2721
}
28-
29-
fn read_to_static(mut source: impl Read) -> &'static str {
30-
let mut input = "".to_owned();
31-
source.read_to_string(&mut input).unwrap();
32-
Box::leak(input.into_boxed_str())
33-
}

examples/abc151-d.rs

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
11
// https://atcoder.jp/contests/abc151/tasks/abc151_d
22

33
use ndarray::Array;
4+
use proconio::input;
5+
use proconio::marker::Bytes;
46
use smallvec::SmallVec;
57

6-
use std::io::{self, Read};
78
use std::{iter, mem};
89

910
fn main() {
10-
let mut input = read_to_static(io::stdin()).split_whitespace();
11-
macro_rules! read {
12-
([$tt:tt]) => (read!([$tt; read!(usize)]));
13-
([$tt:tt; $n:expr]) => ((0..$n).map(|_| read!($tt)).collect::<Vec<_>>());
14-
(($($tt:tt),+)) => (($(read!($tt)),*));
15-
($ty:ty) => (input.next().unwrap().parse::<$ty>().unwrap());
16-
({ Maze<$c:literal, ($h:expr, $w:expr)> }) => {
17-
Array::from_shape_vec(
18-
($h, $w),
19-
itertools::concat((0..$h).map(|_| read!({ Row<$c> }))),
20-
)
21-
.unwrap()
22-
};
23-
({ Row<$c:literal> }) => {
24-
read!({ Bytes }).into_iter().map(|c| c == $c).collect::<Vec<_>>()
25-
};
26-
({ Bytes }) => {
27-
read!(String).into_bytes()
28-
};
11+
input! {
12+
h: usize,
13+
w: usize,
14+
sss: [Bytes; h],
2915
}
3016

31-
let (h, w) = read!((usize, usize));
32-
let maze = read!({ Maze<b'.', (h, w)> });
17+
let maze = Array::from_shape_vec((h, w), itertools::concat(sss))
18+
.unwrap()
19+
.map(|&c| c == b'.');
3320

3421
let neighbors = Array::from_shape_fn((h, w), |(i, j)| {
3522
let mut neighbors = SmallVec::<[_; 4]>::new();
@@ -69,9 +56,3 @@ fn main() {
6956
.unwrap();
7057
println!("{}", ans);
7158
}
72-
73-
fn read_to_static(mut source: impl Read) -> &'static str {
74-
let mut input = "".to_owned();
75-
source.read_to_string(&mut input).unwrap();
76-
Box::leak(input.into_boxed_str())
77-
}

examples/apg4b-ex25.rs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,17 @@
22

33
use fixedbitset::FixedBitSet;
44
use itertools::Itertools as _;
5-
6-
use std::io::{self, Read};
5+
use proconio::input;
76

87
#[allow(clippy::many_single_char_names)]
98
fn main() {
10-
let mut input = read_to_static(io::stdin()).split_whitespace();
11-
macro_rules! read {
12-
([$tt:tt]) => (read!([$tt; read!(usize)]));
13-
([$tt:tt; $n:expr]) => ((0..$n).map(|_| read!($tt)).collect::<Vec<_>>());
14-
(($($tt:tt),+)) => (($(read!($tt)),*));
15-
($ty:ty) => (input.next().unwrap().parse::<$ty>().unwrap());
9+
input! {
10+
a: [usize],
11+
b: [usize],
12+
arg0: String,
13+
args: [usize; if arg0 == "subtract" { 1 } else { 0 }],
1614
}
1715

18-
let a = read!([usize]);
19-
let b = read!([usize]);
20-
let arg0 = read!(String);
21-
let args = read!([usize; if arg0 == "subtract" { 1 } else { 0 }]);
22-
2316
let (a, b) = (a.into_iter().collect(), b.into_iter().collect());
2417

2518
print_set(&match (&*arg0, &*args) {
@@ -61,9 +54,3 @@ fn increment(a: &FixedBitSet) -> FixedBitSet {
6154
fn decrement(a: &FixedBitSet) -> FixedBitSet {
6255
a.ones().map(|x| (x + 49) % 50).collect()
6356
}
64-
65-
fn read_to_static(mut source: impl Read) -> &'static str {
66-
let mut input = "".to_owned();
67-
source.read_to_string(&mut input).unwrap();
68-
Box::leak(input.into_boxed_str())
69-
}

examples/arc065-c.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,17 @@
11
// https://atcoder.jp/contests/arc065/tasks/arc065_a
22

33
use lazy_static::lazy_static;
4+
use proconio::input;
5+
use proconio::marker::Bytes;
46
use regex::bytes::Regex;
57

6-
use std::io::{self, Read};
7-
88
fn main() {
9-
let mut input = read_to_static(io::stdin()).split_whitespace();
10-
macro_rules! read {
11-
([$tt:tt]) => (read!([$tt; read!(usize)]));
12-
([$tt:tt; $n:expr]) => ((0..$n).map(|_| read!($tt)).collect::<Vec<_>>());
13-
(($($tt:tt),+)) => (($(read!($tt)),*));
14-
($ty:ty) => (input.next().unwrap().parse::<$ty>().unwrap());
15-
({ Bytes }) => {
16-
read!(String).into_bytes()
17-
};
9+
input! {
10+
s: Bytes,
1811
}
1912

20-
let s = read!({ Bytes });
21-
2213
lazy_static! {
2314
static ref R: Regex = Regex::new(r"\A(dream(er)?|eraser?)*\z").unwrap();
2415
};
2516
println!("{}", if R.is_match(&s) { "YES" } else { "NO" });
2617
}
27-
28-
fn read_to_static(mut source: impl Read) -> &'static str {
29-
let mut input = "".to_owned();
30-
source.read_to_string(&mut input).unwrap();
31-
Box::leak(input.into_boxed_str())
32-
}

0 commit comments

Comments
 (0)