Skip to content

Commit 6eabc5f

Browse files
author
hir12111
committed
Sorting exams like a champ
1 parent a7d493f commit 6eabc5f

9 files changed

+450
-0
lines changed

Diff for: books.rs

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
struct Scan {
2+
buffer: std::collections::VecDeque<String>,
3+
}
4+
5+
impl Scan {
6+
fn new() -> Scan {
7+
Scan {
8+
buffer: std::collections::VecDeque::new(),
9+
}
10+
}
11+
12+
fn next<T: std::str::FromStr>(&mut self) -> T {
13+
loop {
14+
if let Some(token) = self.buffer.pop_front() {
15+
break token.parse::<T>().ok().unwrap();
16+
}
17+
let mut line = String::new();
18+
std::io::stdin().read_line(&mut line).expect("Fail to read");
19+
self.buffer = line.split_whitespace().map(String::from).collect();
20+
}
21+
}
22+
23+
fn next_n<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
24+
(0..n).map(|_| self.next::<T>()).collect()
25+
}
26+
}
27+
28+
fn _main() {
29+
let mut scan = Scan::new();
30+
let n: usize = scan.next();
31+
let t: usize = scan.next();
32+
let arr: Vec<usize> = scan.next_n(n);
33+
let mut acc = 0usize;
34+
let mut result = 0usize;
35+
let mut left = 0usize;
36+
let mut right = 0usize;
37+
while right < n {
38+
if acc > t {
39+
acc -= arr[left];
40+
left += 1;
41+
} else {
42+
acc += arr[right];
43+
right += 1;
44+
}
45+
if acc <= t {
46+
result = result.max(right - left);
47+
}
48+
}
49+
println!("{}", result);
50+
}
51+
52+
fn main() {
53+
std::thread::Builder::new()
54+
.stack_size(1 << 23)
55+
.spawn(_main)
56+
.unwrap()
57+
.join()
58+
.unwrap();
59+
}

Diff for: dieroll.rs

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
struct Scan {
2+
buffer: std::collections::VecDeque<String>,
3+
}
4+
5+
impl Scan {
6+
fn new() -> Scan {
7+
Scan {
8+
buffer: std::collections::VecDeque::new(),
9+
}
10+
}
11+
12+
fn next<T: std::str::FromStr>(&mut self) -> T {
13+
loop {
14+
if let Some(token) = self.buffer.pop_front() {
15+
break token.parse::<T>().ok().unwrap();
16+
}
17+
let mut line = String::new();
18+
std::io::stdin().read_line(&mut line).expect("Fail to read");
19+
self.buffer = line.split_whitespace().map(String::from).collect();
20+
}
21+
}
22+
}
23+
24+
fn gcd(mut a: usize, mut b: usize) -> usize {
25+
if b > a {
26+
std::mem::swap(&mut a, &mut b);
27+
}
28+
while b != 0 {
29+
let new_b = a % b;
30+
a = b;
31+
b = new_b;
32+
}
33+
if a == 0 {
34+
1
35+
} else {
36+
a
37+
}
38+
}
39+
40+
fn _main() {
41+
let mut scan = Scan::new();
42+
let a: usize = scan.next();
43+
let b: usize = scan.next();
44+
let x = 6 - a.max(b) + 1;
45+
let common = gcd(x, 6);
46+
println!("{}/{}", x / common, 6 / common);
47+
}
48+
49+
fn main() {
50+
std::thread::Builder::new()
51+
.stack_size(1 << 23)
52+
.spawn(_main)
53+
.unwrap()
54+
.join()
55+
.unwrap();
56+
}

Diff for: exams.rs

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
struct Scan {
2+
buffer: std::collections::VecDeque<String>,
3+
}
4+
5+
impl Scan {
6+
fn new() -> Scan {
7+
Scan {
8+
buffer: std::collections::VecDeque::new(),
9+
}
10+
}
11+
12+
fn next<T: std::str::FromStr>(&mut self) -> T {
13+
loop {
14+
if let Some(token) = self.buffer.pop_front() {
15+
break token.parse::<T>().ok().unwrap();
16+
}
17+
let mut line = String::new();
18+
std::io::stdin().read_line(&mut line).expect("Fail to read");
19+
self.buffer = line.split_whitespace().map(String::from).collect();
20+
}
21+
}
22+
}
23+
#[derive(Eq, Ord, PartialOrd, PartialEq)]
24+
struct Exam {
25+
a: usize,
26+
b: usize,
27+
}
28+
fn _main() {
29+
let mut scan = Scan::new();
30+
let n: usize = scan.next();
31+
let mut arr: Vec<Exam> = vec![];
32+
for _ in 0..n {
33+
let a: usize = scan.next();
34+
let b: usize = scan.next();
35+
arr.push(Exam { a: a, b: b });
36+
}
37+
arr.sort();
38+
let mut result = arr[0].a.min(arr[0].b);
39+
for i in 1..n {
40+
let min_date = arr[i].a.min(arr[i].b);
41+
let max_date = arr[i].a.max(arr[i].b);
42+
if min_date >= result {
43+
result = min_date;
44+
} else {
45+
result = max_date;
46+
}
47+
}
48+
println!("{}", result);
49+
}
50+
51+
fn main() {
52+
std::thread::Builder::new()
53+
.stack_size(1 << 23)
54+
.spawn(_main)
55+
.unwrap()
56+
.join()
57+
.unwrap();
58+
}

Diff for: frogjumping.rs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
struct Scan {
2+
buffer: std::collections::VecDeque<String>,
3+
}
4+
5+
impl Scan {
6+
fn new() -> Scan {
7+
Scan {
8+
buffer: std::collections::VecDeque::new(),
9+
}
10+
}
11+
12+
fn next<T: std::str::FromStr>(&mut self) -> T {
13+
loop {
14+
if let Some(token) = self.buffer.pop_front() {
15+
break token.parse::<T>().ok().unwrap();
16+
}
17+
let mut line = String::new();
18+
std::io::stdin().read_line(&mut line).expect("Fail to read");
19+
self.buffer = line.split_whitespace().map(String::from).collect();
20+
}
21+
}
22+
}
23+
24+
fn _main() {
25+
let mut scan = Scan::new();
26+
let t: isize = scan.next();
27+
for _ in 0..t {
28+
let a: i64 = scan.next();
29+
let b: i64 = scan.next();
30+
let k: i64 = scan.next();
31+
let result = (a - b) * (k / 2) + a * (k % 2);
32+
println!("{}", result);
33+
}
34+
}
35+
36+
fn main() {
37+
std::thread::Builder::new()
38+
.stack_size(1 << 23)
39+
.spawn(_main)
40+
.unwrap()
41+
.join()
42+
.unwrap();
43+
}

Diff for: maxinc.rs

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
struct Scan {
2+
buffer: std::collections::VecDeque<String>,
3+
}
4+
5+
impl Scan {
6+
fn new() -> Scan {
7+
Scan {
8+
buffer: std::collections::VecDeque::new(),
9+
}
10+
}
11+
12+
fn next<T: std::str::FromStr>(&mut self) -> T {
13+
loop {
14+
if let Some(token) = self.buffer.pop_front() {
15+
break token.parse::<T>().ok().unwrap();
16+
}
17+
let mut line = String::new();
18+
std::io::stdin().read_line(&mut line).expect("Fail to read");
19+
self.buffer = line.split_whitespace().map(String::from).collect();
20+
}
21+
}
22+
23+
fn next_n<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
24+
(0..n).map(|_| self.next::<T>()).collect()
25+
}
26+
}
27+
28+
fn _main() {
29+
let mut scan = Scan::new();
30+
let n: usize = scan.next();
31+
let arr: Vec<usize> = scan.next_n(n);
32+
let mut result = 0;
33+
let mut acc = 0;
34+
for i in 1..n {
35+
if arr[i] > arr[i - 1] {
36+
acc += 1;
37+
result = result.max(acc);
38+
} else {
39+
acc = 0;
40+
}
41+
}
42+
println!("{}", result + 1);
43+
}
44+
45+
fn main() {
46+
std::thread::Builder::new()
47+
.stack_size(1 << 23)
48+
.spawn(_main)
49+
.unwrap()
50+
.join()
51+
.unwrap();
52+
}

Diff for: modexp.rs

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
struct Scan {
2+
buffer: std::collections::VecDeque<String>,
3+
}
4+
5+
impl Scan {
6+
fn new() -> Scan {
7+
Scan {
8+
buffer: std::collections::VecDeque::new(),
9+
}
10+
}
11+
12+
fn next<T: std::str::FromStr>(&mut self) -> T {
13+
loop {
14+
if let Some(token) = self.buffer.pop_front() {
15+
break token.parse::<T>().ok().unwrap();
16+
}
17+
let mut line = String::new();
18+
std::io::stdin().read_line(&mut line).expect("Fail to read");
19+
self.buffer = line.split_whitespace().map(String::from).collect();
20+
}
21+
}
22+
}
23+
24+
fn _main() {
25+
let mut scan = Scan::new();
26+
let n: usize = scan.next();
27+
let m: usize = scan.next();
28+
if n >= 27 {
29+
println!("{}", m);
30+
} else {
31+
println!("{}", m % (1 << n));
32+
}
33+
}
34+
35+
fn main() {
36+
std::thread::Builder::new()
37+
.stack_size(1 << 23)
38+
.spawn(_main)
39+
.unwrap()
40+
.join()
41+
.unwrap();
42+
}

Diff for: repeatingcipher.rs

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
struct Scan {
2+
buffer: std::collections::VecDeque<String>,
3+
}
4+
5+
impl Scan {
6+
fn new() -> Scan {
7+
Scan {
8+
buffer: std::collections::VecDeque::new(),
9+
}
10+
}
11+
12+
fn next<T: std::str::FromStr>(&mut self) -> T {
13+
loop {
14+
if let Some(token) = self.buffer.pop_front() {
15+
break token.parse::<T>().ok().unwrap();
16+
}
17+
let mut line = String::new();
18+
std::io::stdin().read_line(&mut line).expect("Fail to read");
19+
self.buffer = line.split_whitespace().map(String::from).collect();
20+
}
21+
}
22+
}
23+
24+
fn _main() {
25+
let mut scan = Scan::new();
26+
let n: usize = scan.next();
27+
let arr: Vec<char> = scan.next::<String>().chars().collect();
28+
let mut res: Vec<char> = vec![];
29+
let mut i = 0usize;
30+
let mut cnt = 1usize;
31+
while i < n {
32+
res.push(arr[i]);
33+
i += cnt;
34+
cnt += 1;
35+
}
36+
let res: String = res.iter().collect();
37+
println!("{}", res);
38+
}
39+
40+
fn main() {
41+
std::thread::Builder::new()
42+
.stack_size(1 << 23)
43+
.spawn(_main)
44+
.unwrap()
45+
.join()
46+
.unwrap();
47+
}

0 commit comments

Comments
 (0)