-
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
7 changed files
with
651 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
....12.2023 - Educational Codeforces Round 151 (Rated for Div. 2)/a_zapreshchennoe_chislo.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,57 @@ | ||
//{"name":"A. Запрещенное число","group":"Codeforces - Educational Codeforces Round 151 (Rated for Div. 2)","url":"https://codeforces.com/contest/1845/problem/A","interactive":false,"timeLimit":2000,"tests":[{"input":"5\n10 3 2\n5 2 1\n4 2 1\n7 7 3\n6 1 1\n","output":"YES\n6\n3 1 1 1 1 3\nNO\nYES\n2\n2 2\nYES\n1\n7\nNO\n"}],"testType":"multiNumber","input":{"type":"stdin","fileName":null,"pattern":null},"output":{"type":"stdout","fileName":null,"pattern":null},"languages":{"java":{"taskClass":"AZapreshchennoeChislo"}}} | ||
|
||
#[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 mut n = input.i32(); | ||
let k = input.i32(); | ||
let x = input.i32(); | ||
let ok = if x != 1 { | ||
vec![1; n as usize] | ||
} else if k == 1 { | ||
vec![] | ||
} else { | ||
let mut res = vec![]; | ||
if n % 2 == 1 && n >= 3 && k >= 3 { | ||
res.push(3); | ||
n -= 3; | ||
} | ||
while n != 0 && n > 1 && n % 2 == 0 { | ||
res.push(2); | ||
n -= 2; | ||
} | ||
res | ||
}; | ||
if ok.is_empty() { | ||
out.println("NO"); | ||
} else { | ||
out.println("YES"); | ||
out.println(ok.len()); | ||
out.println(ok); | ||
} | ||
} | ||
|
||
pub(crate) fn run(mut input: Input, mut output: Output) -> bool { | ||
let t = input.read(); | ||
for i in 0usize..t { | ||
solve(&mut input, &mut output, i + 1); | ||
} | ||
output.flush(); | ||
true | ||
} | ||
|
||
//START MAIN | ||
|
||
fn main() { | ||
const PROBLEM_NAME: &str = "a_zapreshchennoe_chislo"; | ||
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 |
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,47 @@ | ||
//{"name":"A. 2023","group":"Codeforces - Good Bye 2023","url":"https://codeforces.com/contest/1916/problem/0","interactive":false,"timeLimit":1000,"tests":[{"input":"7\n2 2\n5 2\n3 1\n7 17 7\n4 2\n1 289 1 1\n3 1\n7 17 17\n1 1\n289\n1 1\n2023\n1 3\n1\n","output":"NO\nNO\nYES\n7 1\nYES\n1\nYES\n7\nYES\n1\nYES\n7 17 17\n"}],"testType":"multiNumber","input":{"type":"stdin","fileName":null,"pattern":null},"output":{"type":"stdout","fileName":null,"pattern":null},"languages":{"java":{"taskClass":"A2023"}}} | ||
|
||
#[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 n = input.usize(); | ||
let k = input.usize(); | ||
let b = input.vec::<i64>(n); | ||
let mut mul = 1; | ||
for &x in b.iter() { | ||
mul *= x; | ||
} | ||
if 2023 % mul == 0 { | ||
out.println("YES"); | ||
for _ in 0..k - 1 { | ||
out.print("1 "); | ||
} | ||
out.println(2023 / mul); | ||
} else { | ||
out.println("NO"); | ||
} | ||
} | ||
|
||
pub(crate) fn run(mut input: Input, mut output: Output) -> bool { | ||
let t = input.read(); | ||
for i in 0usize..t { | ||
solve(&mut input, &mut output, i + 1); | ||
} | ||
output.flush(); | ||
true | ||
} | ||
|
||
//START MAIN | ||
|
||
fn main() { | ||
const PROBLEM_NAME: &str = "a2023"; | ||
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 |
40 changes: 40 additions & 0 deletions
40
archive/2023/12/30.12.2023 - Good Bye 2023/b_dva_delitelya.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,40 @@ | ||
//{"name":"B. Два делителя","group":"Codeforces - Good Bye 2023","url":"https://codeforces.com/contest/1916/problem/B","interactive":false,"timeLimit":1000,"tests":[{"input":"8\n2 3\n1 2\n3 11\n1 5\n5 10\n4 6\n3 9\n250000000 500000000\n","output":"6\n4\n33\n25\n20\n12\n27\n1000000000\n"}],"testType":"multiNumber","input":{"type":"stdin","fileName":null,"pattern":null},"output":{"type":"stdout","fileName":null,"pattern":null},"languages":{"java":{"taskClass":"BDvaDelitelya"}}} | ||
|
||
#[allow(unused)] | ||
use algo_lib::dbg; | ||
use algo_lib::io::input::Input; | ||
use algo_lib::io::output::Output; | ||
use algo_lib::math::gcd::lcm; | ||
|
||
fn solve(input: &mut Input, out: &mut Output, _test_case: usize) { | ||
let x = input.i64(); | ||
let y = input.i64(); | ||
let lcm = lcm(x, y); | ||
if lcm == y { | ||
out.println(lcm * (y / x)); | ||
} else { | ||
out.println(lcm); | ||
} | ||
} | ||
|
||
pub(crate) fn run(mut input: Input, mut output: Output) -> bool { | ||
let t = input.read(); | ||
for i in 0usize..t { | ||
solve(&mut input, &mut output, i + 1); | ||
} | ||
output.flush(); | ||
true | ||
} | ||
|
||
//START MAIN | ||
|
||
fn main() { | ||
const PROBLEM_NAME: &str = "b_dva_delitelya"; | ||
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 |
50 changes: 50 additions & 0 deletions
50
archive/2023/12/30.12.2023 - Good Bye 2023/c_trenirovka_pered_olimpiadoi.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,50 @@ | ||
//{"name":"C. Тренировка перед олимпиадой","group":"Codeforces - Good Bye 2023","url":"https://codeforces.com/contest/1916/problem/C","interactive":false,"timeLimit":1000,"tests":[{"input":"4\n1\n31\n6\n6 3 7 2 5 4\n3\n3 10 11\n5\n7 13 11 19 1\n","output":"31\n6 8 16 18 22 26\n3 12 24\n7 20 30 48 50\n"}],"testType":"multiNumber","input":{"type":"stdin","fileName":null,"pattern":null},"output":{"type":"stdout","fileName":null,"pattern":null},"languages":{"java":{"taskClass":"CTrenirovkaPeredOlimpiadoi"}}} | ||
|
||
#[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 n = input.usize(); | ||
let a = input.vec::<i64>(n); | ||
let mut res = vec![]; | ||
let mut sum = 0; | ||
let mut cnt_odd = 0; | ||
|
||
for (it, &x) in a.iter().enumerate() { | ||
sum += x; | ||
if x % 2 == 1 { | ||
cnt_odd += 1; | ||
} | ||
let mut r = sum - cnt_odd; | ||
r += (cnt_odd + 1) / 3 * 2; | ||
if it == 0 { | ||
r = sum; | ||
} | ||
res.push(r); | ||
} | ||
out.println(res); | ||
} | ||
|
||
pub(crate) fn run(mut input: Input, mut output: Output) -> bool { | ||
let t = input.read(); | ||
for i in 0usize..t { | ||
solve(&mut input, &mut output, i + 1); | ||
} | ||
output.flush(); | ||
true | ||
} | ||
|
||
//START MAIN | ||
|
||
fn main() { | ||
const PROBLEM_NAME: &str = "c_trenirovka_pered_olimpiadoi"; | ||
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 |
163 changes: 163 additions & 0 deletions
163
archive/2023/12/30.12.2023 - Good Bye 2023/d_matematicheskoe_zadanie.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,163 @@ | ||
//{"name":"D. Математическое задание","group":"Codeforces - Good Bye 2023","url":"https://codeforces.com/contest/1916/problem/D","interactive":false,"timeLimit":1000,"tests":[{"input":"3\n1\n3\n5\n","output":"1\n169\n196\n961\n16384\n31684\n36481\n38416\n43681\n"}],"testType":"single","input":{"type":"stdin","fileName":null,"pattern":null},"output":{"type":"stdout","fileName":null,"pattern":null},"languages":{"java":{"taskClass":"DMatematicheskoeZadanie"}}} | ||
|
||
use std::collections::{HashMap, HashSet}; | ||
|
||
use algo_lib::collections::array_2d::Array2D; | ||
#[allow(unused)] | ||
use algo_lib::dbg; | ||
use algo_lib::io::input::Input; | ||
use algo_lib::io::output::Output; | ||
use algo_lib::misc::gen_vector::gen_vec; | ||
use algo_lib::misc::rand::Random; | ||
|
||
fn sq(a: &[i32]) -> Vec<i32> { | ||
let mut res = vec![0; a.len() * 2 + 1]; | ||
for i in 0..a.len() { | ||
for j in 0..a.len() { | ||
res[i + j] += a[i] * a[j]; | ||
} | ||
} | ||
for i in 0..res.len() - 1 { | ||
res[i + 1] += res[i] / 10; | ||
res[i] %= 10; | ||
} | ||
while res.len() > 1 && res[res.len() - 1] == 0 { | ||
res.pop(); | ||
} | ||
assert!(res[res.len() - 1] < 10); | ||
res | ||
} | ||
|
||
fn mask(a: &[i32]) -> Vec<i32> { | ||
let mut a = a.to_vec(); | ||
a.sort(); | ||
a | ||
} | ||
|
||
fn stress() {} | ||
|
||
fn solve(input: &mut Input, out: &mut Output, _test_case: usize) { | ||
let mut seen = HashMap::<(usize, Vec<i32>), HashSet<_>>::new(); | ||
let mut ok = vec![false; 100]; | ||
let mut cnt = 0; | ||
for it in 1.. { | ||
// dbg!(it); | ||
let mut rnd = Random::new(787788 + it); | ||
let n = rnd.gen(1..51); | ||
let mut a = vec![0; n]; | ||
a[n - 1] = 1; | ||
for it in 0..rnd.gen(0..n) { | ||
a[rnd.gen(0..n)] = 1; | ||
} | ||
|
||
let a2 = sq(&a); | ||
if a2 == [0] { | ||
continue; | ||
} | ||
let mask = mask(&a2); | ||
let len = a2.len(); | ||
if ok[len] { | ||
continue; | ||
} | ||
if seen.entry((len, mask.clone())).or_default().contains(&a2) { | ||
continue; | ||
} | ||
seen.entry((len, mask.clone())) | ||
.or_default() | ||
.insert(a2.clone()); | ||
if seen.entry((len, mask.clone())).or_default().len() == len && !ok[len] && len % 2 == 1 { | ||
ok[len] = true; | ||
cnt += 1; | ||
// TODO:!!! | ||
|
||
// dbg!(len, cnt); | ||
if cnt == 44 { | ||
break; | ||
} | ||
} | ||
} | ||
for z in 1..=99 { | ||
if z % 2 == 1 && !ok[z] { | ||
// dbg!(z); | ||
} | ||
} | ||
|
||
for it in 1.. { | ||
// dbg!(it); | ||
let mut rnd = Random::new(787788 + it); | ||
let n = rnd.gen(1..8); | ||
let mut a = vec![0; n]; | ||
a[n - 1] = 1; | ||
for it in 0..rnd.gen(0..n) { | ||
a[rnd.gen(0..n)] = rnd.gen(0..4); | ||
} | ||
if rnd.gen_bool() { | ||
a = gen_vec(n, |_| rnd.gen(0..10)); | ||
} | ||
|
||
let a2 = sq(&a); | ||
if a2 == [0] { | ||
continue; | ||
} | ||
let mask = mask(&a2); | ||
let len = a2.len(); | ||
if ok[len] { | ||
continue; | ||
} | ||
if seen.entry((len, mask.clone())).or_default().contains(&a2) { | ||
continue; | ||
} | ||
seen.entry((len, mask.clone())) | ||
.or_default() | ||
.insert(a2.clone()); | ||
if seen.entry((len, mask.clone())).or_default().len() == len && !ok[len] && len % 2 == 1 { | ||
ok[len] = true; | ||
cnt += 1; | ||
// TODO:!!! | ||
|
||
dbg!(len, cnt); | ||
if cnt == 50 { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
let tc = input.usize(); | ||
for _ in 0..tc { | ||
let n = input.usize(); | ||
let mut found = false; | ||
dbg!(n); | ||
for ((len, mask), v) in seen.iter() { | ||
if *len == n && v.len() == n { | ||
for value in v.iter() { | ||
for &z in value.iter().rev() { | ||
out.print(z); | ||
} | ||
out.println(""); | ||
} | ||
found = true; | ||
break; | ||
} | ||
} | ||
assert!(found); | ||
} | ||
} | ||
|
||
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_matematicheskoe_zadanie"; | ||
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.