-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
411 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...2025/02/01.02.2025 - Ethflow Round 1 (Codeforces Round 1001, Div. 1 + Div. 2)/a_stroka.rs
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,39 @@ | ||
//{"name":"A. Строка","group":"Codeforces - Ethflow Round 1 (Codeforces Round 1001, Div. 1 + Div. 2)","url":"https://codeforces.com/contest/2062/problem/0","interactive":false,"timeLimit":1000,"tests":[{"input":"5\n1\n000\n1001\n10101\n01100101011101\n","output":"1\n0\n2\n3\n8\n"}],"testType":"single","input":{"type":"stdin","fileName":null,"pattern":null},"output":{"type":"stdout","fileName":null,"pattern":null},"languages":{"java":{"taskClass":"AStroka"}}} | ||
|
||
#[allow(unused)] | ||
use algo_lib::dbg; | ||
use algo_lib::io::input::Input; | ||
use algo_lib::io::output::Output; | ||
|
||
fn solve(input: &mut Input, out: &mut Output, _test_case: usize) { | ||
let tc = input.usize(); | ||
for _ in 0..tc { | ||
let s = input.string(); | ||
let mut cnt = 0; | ||
for &x in s.iter() { | ||
if x == b'1' { | ||
cnt += 1; | ||
} | ||
} | ||
out.println(cnt); | ||
} | ||
} | ||
|
||
pub(crate) fn run(mut input: Input, mut output: Output) -> bool { | ||
solve(&mut input, &mut output, 1); | ||
output.flush(); | ||
true | ||
} | ||
|
||
//START MAIN | ||
|
||
fn main() { | ||
const PROBLEM_NAME: &str = "a_stroka"; | ||
use algo_lib::tester::helper::*; | ||
|
||
run_tests(PROBLEM_NAME, run); | ||
// run_single_test(PROBLEM_NAME, run, "1"); | ||
// run_stress(stress); | ||
// run_locally(run); | ||
} | ||
//END MAIN |
48 changes: 48 additions & 0 deletions
48
...2.2025 - Ethflow Round 1 (Codeforces Round 1001, Div. 1 + Div. 2)/b_chasovoi_mekhanizm.rs
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,48 @@ | ||
//{"name":"B. Часовой механизм","group":"Codeforces - Ethflow Round 1 (Codeforces Round 1001, Div. 1 + Div. 2)","url":"https://codeforces.com/contest/2062/problem/B","interactive":false,"timeLimit":1500,"tests":[{"input":"5\n2\n4 10\n2\n2 2\n3\n4 10 5\n3\n5 3 5\n5\n12 13 25 17 30\n","output":"YES\nNO\nNO\nYES\nYES\n"}],"testType":"single","input":{"type":"stdin","fileName":null,"pattern":null},"output":{"type":"stdout","fileName":null,"pattern":null},"languages":{"java":{"taskClass":"BChasovoiMekhanizm"}}} | ||
|
||
#[allow(unused)] | ||
use algo_lib::dbg; | ||
use algo_lib::io::input::Input; | ||
use algo_lib::io::output::Output; | ||
|
||
fn solve(input: &mut Input, out: &mut Output, _test_case: usize) { | ||
let tc = input.usize(); | ||
for _ in 0..tc { | ||
let n = input.usize(); | ||
let a = input.vec::<usize>(n); | ||
let mut ok = true; | ||
for i in 0..n { | ||
if a[i] == 1 { | ||
ok = false; | ||
} | ||
let len = (2 * i).max(2 * (n - 1 - i)); | ||
if a[i] <= len { | ||
ok = false; | ||
} | ||
} | ||
if ok { | ||
out.println("YES"); | ||
} else { | ||
out.println("NO"); | ||
} | ||
} | ||
} | ||
|
||
pub(crate) fn run(mut input: Input, mut output: Output) -> bool { | ||
solve(&mut input, &mut output, 1); | ||
output.flush(); | ||
true | ||
} | ||
|
||
//START MAIN | ||
|
||
fn main() { | ||
const PROBLEM_NAME: &str = "b_chasovoi_mekhanizm"; | ||
use algo_lib::tester::helper::*; | ||
|
||
run_tests(PROBLEM_NAME, run); | ||
// run_single_test(PROBLEM_NAME, run, "1"); | ||
// run_stress(stress); | ||
// run_locally(run); | ||
} | ||
//END MAIN |
61 changes: 61 additions & 0 deletions
61
...02.2025 - Ethflow Round 1 (Codeforces Round 1001, Div. 1 + Div. 2)/c_chirno_ioperatsii.rs
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,61 @@ | ||
//{"name":"C. Чирно и операции","group":"Codeforces - Ethflow Round 1 (Codeforces Round 1001, Div. 1 + Div. 2)","url":"https://codeforces.com/contest/2062/problem/C","interactive":false,"timeLimit":2000,"tests":[{"input":"5\n1\n-1000\n2\n5 -3\n2\n1000 1\n9\n9 7 9 -9 9 -8 7 -8 9\n11\n678 201 340 444 453 922 128 987 127 752 0\n","output":"-1000\n8\n1001\n2056\n269891\n"}],"testType":"single","input":{"type":"stdin","fileName":null,"pattern":null},"output":{"type":"stdout","fileName":null,"pattern":null},"languages":{"java":{"taskClass":"CChirnoIOperatsii"}}} | ||
|
||
use std::collections::{HashSet, VecDeque}; | ||
|
||
#[allow(unused)] | ||
use algo_lib::dbg; | ||
use algo_lib::io::input::Input; | ||
use algo_lib::io::output::Output; | ||
|
||
fn solve(input: &mut Input, out: &mut Output, _test_case: usize) { | ||
let tc = input.usize(); | ||
for _ in 0..tc { | ||
let n = input.usize(); | ||
let a = input.vec::<i64>(n); | ||
let mut seen = HashSet::new(); | ||
let mut queue = VecDeque::new(); | ||
queue.push_back(a.clone()); | ||
seen.insert(a.clone()); | ||
let mut max_sum = i64::MIN; | ||
while let Some(cur) = queue.pop_front() { | ||
let sum = cur.iter().sum::<i64>(); | ||
max_sum = max_sum.max(sum); | ||
{ | ||
let mut next = cur.clone(); | ||
next.reverse(); | ||
if seen.insert(next.clone()) { | ||
queue.push_back(next); | ||
} | ||
} | ||
if cur.len() > 1 { | ||
let mut deltas = vec![]; | ||
for i in 0..cur.len() - 1 { | ||
deltas.push(cur[i] - cur[i + 1]); | ||
} | ||
if seen.insert(deltas.clone()) { | ||
queue.push_back(deltas); | ||
} | ||
} | ||
} | ||
out.println(max_sum); | ||
} | ||
} | ||
|
||
pub(crate) fn run(mut input: Input, mut output: Output) -> bool { | ||
solve(&mut input, &mut output, 1); | ||
output.flush(); | ||
true | ||
} | ||
|
||
//START MAIN | ||
|
||
fn main() { | ||
const PROBLEM_NAME: &str = "c_chirno_ioperatsii"; | ||
use algo_lib::tester::helper::*; | ||
|
||
run_tests(PROBLEM_NAME, run); | ||
// run_single_test(PROBLEM_NAME, run, "1"); | ||
// run_stress(stress); | ||
// run_locally(run); | ||
} | ||
//END MAIN |
75 changes: 75 additions & 0 deletions
75
...5 - Ethflow Round 1 (Codeforces Round 1001, Div. 1 + Div. 2)/d_sbalansirovannoe_derevo.rs
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,75 @@ | ||
//{"name":"D. Сбалансированное дерево","group":"Codeforces - Ethflow Round 1 (Codeforces Round 1001, Div. 1 + Div. 2)","url":"https://codeforces.com/contest/2062/problem/D","interactive":false,"timeLimit":3000,"tests":[{"input":"6\n4\n0 11\n6 6\n0 0\n5 5\n2 1\n3 1\n4 3\n7\n1 1\n0 5\n0 5\n2 2\n2 2\n2 2\n2 2\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n4\n1 1\n1 1\n1 1\n0 0\n1 4\n2 4\n3 4\n7\n0 20\n0 20\n0 20\n0 20\n3 3\n4 4\n5 5\n1 2\n1 3\n1 4\n2 5\n3 6\n4 7\n5\n1000000000 1000000000\n0 0\n1000000000 1000000000\n0 0\n1000000000 1000000000\n3 2\n2 1\n1 4\n4 5\n6\n21 88\n57 81\n98 99\n61 76\n15 50\n23 67\n2 1\n3 2\n4 3\n5 3\n6 4\n","output":"11\n3\n3\n5\n3000000000\n98\n"}],"testType":"single","input":{"type":"stdin","fileName":null,"pattern":null},"output":{"type":"stdout","fileName":null,"pattern":null},"languages":{"java":{"taskClass":"DSbalansirovannoeDerevo"}}} | ||
|
||
#[allow(unused)] | ||
use algo_lib::dbg; | ||
use algo_lib::io::input::Input; | ||
use algo_lib::io::output::Output; | ||
use algo_lib::misc::rec_function::{Callable2, RecursiveFunction2}; | ||
|
||
fn solve(input: &mut Input, out: &mut Output, _test_case: usize) { | ||
let tc = input.usize(); | ||
for _ in 0..tc { | ||
let n = input.usize(); | ||
let mut left = vec![0; n]; | ||
let mut right = vec![0; n]; | ||
let mut g = vec![vec![]; n]; | ||
for i in 0..n { | ||
left[i] = input.i64(); | ||
right[i] = input.i64(); | ||
} | ||
for _ in 0..n - 1 { | ||
let fr = input.usize() - 1; | ||
let to = input.usize() - 1; | ||
g[fr].push(to); | ||
g[to].push(fr); | ||
} | ||
let mut root = 0; | ||
while g[root].len() > 1 { | ||
root += 1; | ||
} | ||
let mut res = 0; | ||
let root_val = RecursiveFunction2::new(|f, v: usize, p: usize| -> i64 { | ||
let mut children = vec![]; | ||
for &to in g[v].iter() { | ||
if to == p { | ||
continue; | ||
} | ||
let ch = f.call(to, v); | ||
children.push(ch); | ||
} | ||
children.sort(); | ||
if children.is_empty() { | ||
return left[v]; | ||
} | ||
let target = children[children.len() - 1]; | ||
let value = target.clamp(left[v], right[v]); | ||
for &x in children.iter() { | ||
if x > value { | ||
res += x - value; | ||
} | ||
} | ||
value | ||
}) | ||
.call(root, root); | ||
out.println(root_val + res); | ||
} | ||
} | ||
|
||
pub(crate) fn run(mut input: Input, mut output: Output) -> bool { | ||
solve(&mut input, &mut output, 1); | ||
output.flush(); | ||
true | ||
} | ||
|
||
//START MAIN | ||
|
||
fn main() { | ||
const PROBLEM_NAME: &str = "d_sbalansirovannoe_derevo"; | ||
use algo_lib::tester::helper::*; | ||
|
||
run_tests(PROBLEM_NAME, run); | ||
// run_single_test(PROBLEM_NAME, run, "1"); | ||
// run_stress(stress); | ||
// run_locally(run); | ||
} | ||
//END MAIN |
87 changes: 87 additions & 0 deletions
87
...25 - Ethflow Round 1 (Codeforces Round 1001, Div. 1 + Div. 2)/e1_igra_prostaya_versiya.rs
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,87 @@ | ||
//{"name":"E1. Игра (простая версия)","group":"Codeforces - Ethflow Round 1 (Codeforces Round 1001, Div. 1 + Div. 2)","url":"https://codeforces.com/contest/2062/problem/E1","interactive":false,"timeLimit":4000,"tests":[{"input":"5\n4\n2 2 4 3\n1 2\n1 3\n2 4\n5\n1 2 3 4 5\n1 2\n2 3\n3 4\n4 5\n3\n1 2 3\n1 2\n1 3\n5\n3 1 3 4 5\n1 2\n2 3\n3 4\n4 5\n10\n1 2 3 2 4 3 3 4 4 3\n1 4\n4 6\n7 4\n6 9\n6 5\n7 8\n1 2\n2 3\n2 10\n","output":"2\n0\n2\n2\n10\n"}],"testType":"single","input":{"type":"stdin","fileName":null,"pattern":null},"output":{"type":"stdout","fileName":null,"pattern":null},"languages":{"java":{"taskClass":"E1IgraProstayaVersiya"}}} | ||
|
||
#[allow(unused)] | ||
use algo_lib::dbg; | ||
use algo_lib::io::input::Input; | ||
use algo_lib::io::output::Output; | ||
use algo_lib::misc::rec_function::{Callable2, RecursiveFunction2}; | ||
use algo_lib::misc::vec_apply_delta::ApplyDelta; | ||
use algo_lib::seg_trees::fenwick::Fenwick; | ||
|
||
fn solve(input: &mut Input, out: &mut Output, _test_case: usize) { | ||
let tc = input.usize(); | ||
for _ in 0..tc { | ||
let n = input.usize(); | ||
let w = input.vec::<usize>(n).sub_from_all(1); | ||
let mut g = vec![vec![]; n]; | ||
for _ in 0..n - 1 { | ||
let u = input.usize() - 1; | ||
let v = input.usize() - 1; | ||
g[u].push(v); | ||
g[v].push(u); | ||
} | ||
let mut tin = vec![0; n]; | ||
let mut tout = vec![0; n]; | ||
let mut timer = 0; | ||
RecursiveFunction2::new(|f, v: usize, p: usize| { | ||
tin[v] = timer; | ||
timer += 1; | ||
for &to in g[v].iter() { | ||
if to == p { | ||
continue; | ||
} | ||
f.call(to, v); | ||
} | ||
tout[v] = timer; | ||
timer += 1; | ||
}) | ||
.call(0, 0); | ||
let mut by_w = vec![vec![]; n]; | ||
for i in 0..n { | ||
by_w[w[i]].push(i); | ||
} | ||
let mut f = Fenwick::new(timer); | ||
let mut res_v = n; | ||
let mut cnt_alive = 0; | ||
for w in (0..n).rev() { | ||
for &v in by_w[w].iter() { | ||
let inside = f.get_range_sum(tin[v]..tout[v] + 1); | ||
if inside != cnt_alive { | ||
res_v = v; | ||
break; | ||
} | ||
} | ||
if res_v != n { | ||
break; | ||
} | ||
for &v in by_w[w].iter() { | ||
f.add(tin[v], 1); | ||
cnt_alive += 1; | ||
} | ||
} | ||
if res_v == n { | ||
out.println(0); | ||
} else { | ||
out.println(res_v + 1); | ||
} | ||
} | ||
} | ||
|
||
pub(crate) fn run(mut input: Input, mut output: Output) -> bool { | ||
solve(&mut input, &mut output, 1); | ||
output.flush(); | ||
true | ||
} | ||
|
||
//START MAIN | ||
|
||
fn main() { | ||
const PROBLEM_NAME: &str = "e1_igra_prostaya_versiya"; | ||
use algo_lib::tester::helper::*; | ||
|
||
run_tests(PROBLEM_NAME, run); | ||
// run_single_test(PROBLEM_NAME, run, "1"); | ||
// run_stress(stress); | ||
// run_locally(run); | ||
} | ||
//END MAIN |
Oops, something went wrong.