AC043 in rust, finished all. (D doesn't get tested correctly locally)
This commit is contained in:
11
atcoder/beginner_contests/abc043/src/bin/a.rs
Normal file
11
atcoder/beginner_contests/abc043/src/bin/a.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
use proconio::input;
|
||||
|
||||
fn main() {
|
||||
input!{
|
||||
n: u32,
|
||||
};
|
||||
|
||||
let result = n * (n + 1) / 2;
|
||||
|
||||
println!("{}", {result});
|
||||
}
|
||||
21
atcoder/beginner_contests/abc043/src/bin/b.rs
Normal file
21
atcoder/beginner_contests/abc043/src/bin/b.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use proconio::input;
|
||||
|
||||
fn main() {
|
||||
input!{
|
||||
s: String,
|
||||
};
|
||||
|
||||
let mut result = String::new();
|
||||
|
||||
for c in s.chars() {
|
||||
if c == '0' {
|
||||
result.push('0');
|
||||
} else if c == '1' {
|
||||
result.push('1');
|
||||
} else {
|
||||
result.pop();
|
||||
}
|
||||
}
|
||||
|
||||
println!("{}", {result});
|
||||
}
|
||||
28
atcoder/beginner_contests/abc043/src/bin/c.rs
Normal file
28
atcoder/beginner_contests/abc043/src/bin/c.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use proconio::input;
|
||||
|
||||
fn cost(target: i32, numbers: &[i32]) -> i32 {
|
||||
let mut result = 0;
|
||||
|
||||
for n in numbers {
|
||||
result += (target - n) * (target - n)
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
fn main() {
|
||||
input!{
|
||||
n: i32,
|
||||
a: [i32; n],
|
||||
};
|
||||
|
||||
let mut min = std::i32::MAX;
|
||||
for t in -100..=100 {
|
||||
let r = cost(t, &a);
|
||||
if r < min {
|
||||
min = r;
|
||||
}
|
||||
}
|
||||
|
||||
println!("{}", {min});
|
||||
}
|
||||
44
atcoder/beginner_contests/abc043/src/bin/d.rs
Normal file
44
atcoder/beginner_contests/abc043/src/bin/d.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
use proconio::input;
|
||||
|
||||
fn main() {
|
||||
input!{
|
||||
s: String,
|
||||
};
|
||||
|
||||
let mut cs = s.chars();
|
||||
let l = s.len();
|
||||
|
||||
if l == 2 {
|
||||
let a = cs.next().unwrap();
|
||||
let b = cs.next().unwrap();
|
||||
|
||||
if a == b {
|
||||
println!("1 2");
|
||||
} else{
|
||||
println!("-1 -1");
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
let mut past_chars = [' '; 3];
|
||||
past_chars[1] = cs.next().unwrap();
|
||||
past_chars[2] = cs.next().unwrap();
|
||||
|
||||
for i in 2..l {
|
||||
past_chars[0] = past_chars[1];
|
||||
past_chars[1] = past_chars[2];
|
||||
past_chars[2] = cs.next().unwrap();
|
||||
|
||||
let mut sorting = [' '; 3];
|
||||
sorting.copy_from_slice(&past_chars);
|
||||
sorting.sort();
|
||||
|
||||
if sorting[0] == sorting[1] || sorting[1] == sorting[2] {
|
||||
println!("{} {}", {i-1}, {i+1});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
println!("-1 -1");
|
||||
}
|
||||
Reference in New Issue
Block a user