結果
問題 | No.2358 xy+yz+zx=N |
ユーザー | tipstar0125 |
提出日時 | 2023-06-24 11:06:56 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 794 ms / 2,000 ms |
コード長 | 7,014 bytes |
コンパイル時間 | 13,656 ms |
コンパイル使用メモリ | 381,380 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-01 17:48:39 |
合計ジャッジ時間 | 18,628 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 4 ms
5,376 KB |
testcase_08 | AC | 792 ms
5,376 KB |
testcase_09 | AC | 794 ms
5,376 KB |
testcase_10 | AC | 782 ms
5,376 KB |
testcase_11 | AC | 787 ms
5,376 KB |
testcase_12 | AC | 601 ms
5,376 KB |
ソースコード
#![allow(non_snake_case)] #![allow(unused_imports)] #![allow(unused_macros)] #![allow(clippy::needless_range_loop)] #![allow(clippy::comparison_chain)] #![allow(clippy::nonminimal_bool)] #![allow(clippy::neg_multiply)] #![allow(dead_code)] use std::cmp::Reverse; use std::collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque}; #[derive(Default)] struct Solver {} impl Solver { fn solve(&mut self) { input! { n: usize } let mut st = BTreeSet::new(); for x in 0..=n { for y in 0..=n { if x * y > n { break; } let p = x + y; if p == 0 { continue; } if (n - x * y) % p == 0 { let mut v = vec![x, y, (n - x * y) / p]; v.sort(); st.insert(v); } } } let mut res = vec![]; for v in st { if v[0] == v[1] && v[1] == v[2] { res.push(format!("{} {} {}", v[0], v[1], v[2])); } else if v[0] != v[1] && v[1] != v[2] && v[2] != v[0] { // 6 ord res.push(format!("{} {} {}", v[0], v[1], v[2])); res.push(format!("{} {} {}", v[1], v[2], v[0])); res.push(format!("{} {} {}", v[2], v[0], v[1])); res.push(format!("{} {} {}", v[0], v[2], v[1])); res.push(format!("{} {} {}", v[1], v[0], v[2])); res.push(format!("{} {} {}", v[2], v[1], v[0])); } else { // 2 ord res.push(format!("{} {} {}", v[0], v[1], v[2])); res.push(format!("{} {} {}", v[1], v[2], v[0])); res.push(format!("{} {} {}", v[2], v[0], v[1])); } } // let mut ans = vec![]; // let MAX = (N as f64).sqrt().ceil() as usize; // for x in 0..=MAX { // for y in x..=MAX { // if N < x * y || x + y == 0 { // continue; // } // if (N - x * y) % (x + y) != 0 { // continue; // } // let z = (N - x * y) / (x + y); // if z < y { // continue; // } // let v = vec![x, y, z]; // let mut a = gen_perm(v); // a.sort(); // a.dedup(); // ans.extend(a); // } // } // ans.sort(); // ans.dedup(); // println!("{}", ans.len()); // for a in ans { // println!("{} {} {}", a[0], a[1], a[2]); // } println!("{}", res.len()); for r in res { println!("{}", r); } } } fn join_to_string<T: std::string::ToString>(v: &[T], sep: &str) -> String { v.iter() .fold("".to_string(), |s, x| s + x.to_string().as_str() + sep) } pub fn gen_perm<T>(v: Vec<T>) -> Vec<Vec<T>> where T: Clone, { let num_of_chars = v.len(); let mut result = Vec::<Vec<T>>::new(); result.push(v); for n in 0..num_of_chars { let result_len = result.len(); for result_idx in 0..(result_len) { for i in (n + 1)..num_of_chars { let mut v_new = result[result_idx].clone(); v_new.swap(n, i); result.push(v_new); } } } result } fn main() { std::thread::Builder::new() .stack_size(128 * 1024 * 1024) .spawn(|| Solver::default().solve()) .unwrap() .join() .unwrap(); } // fn read<T: std::str::FromStr>() -> T { // let mut s = String::new(); // std::io::stdin().read_line(&mut s).ok(); // s.trim().parse().ok().unwrap() // } // fn read_vec<T: std::str::FromStr>() -> Vec<T> { // read::<String>() // .split_whitespace() // .map(|e| e.parse().ok().unwrap()) // .collect() // } #[macro_export] macro_rules! input { () => {}; (mut $var:ident: $t:tt, $($rest:tt)*) => { let mut $var = __input_inner!($t); input!($($rest)*) }; ($var:ident: $t:tt, $($rest:tt)*) => { let $var = __input_inner!($t); input!($($rest)*) }; (mut $var:ident: $t:tt) => { let mut $var = __input_inner!($t); }; ($var:ident: $t:tt) => { let $var = __input_inner!($t); }; } #[macro_export] macro_rules! __input_inner { (($($t:tt),*)) => { ($(__input_inner!($t)),*) }; ([$t:tt; $n:expr]) => { (0..$n).map(|_| __input_inner!($t)).collect::<Vec<_>>() }; ([$t:tt]) => {{ let n = __input_inner!(usize); (0..n).map(|_| __input_inner!($t)).collect::<Vec<_>>() }}; (chars) => { __input_inner!(String).chars().collect::<Vec<_>>() }; (bytes) => { __input_inner!(String).into_bytes() }; (usize1) => { __input_inner!(usize) - 1 }; ($t:ty) => { $crate::read::<$t>() }; } #[macro_export] macro_rules! println { () => { $crate::write(|w| { use std::io::Write; std::writeln!(w).unwrap() }) }; ($($arg:tt)*) => { $crate::write(|w| { use std::io::Write; std::writeln!(w, $($arg)*).unwrap() }) }; } #[macro_export] macro_rules! print { ($($arg:tt)*) => { $crate::write(|w| { use std::io::Write; std::write!(w, $($arg)*).unwrap() }) }; } #[macro_export] macro_rules! flush { () => { $crate::write(|w| { use std::io::Write; w.flush().unwrap() }) }; } pub fn read<T>() -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, { use std::cell::RefCell; use std::io::*; thread_local! { pub static STDIN: RefCell<StdinLock<'static>> = RefCell::new(stdin().lock()); } STDIN.with(|r| { let mut r = r.borrow_mut(); let mut s = vec![]; loop { let buf = r.fill_buf().unwrap(); if buf.is_empty() { break; } if let Some(i) = buf.iter().position(u8::is_ascii_whitespace) { s.extend_from_slice(&buf[..i]); r.consume(i + 1); if !s.is_empty() { break; } } else { s.extend_from_slice(buf); let n = buf.len(); r.consume(n); } } std::str::from_utf8(&s).unwrap().parse().unwrap() }) } pub fn write<F>(f: F) where F: FnOnce(&mut std::io::BufWriter<std::io::StdoutLock>), { use std::cell::RefCell; use std::io::*; thread_local! { pub static STDOUT: RefCell<BufWriter<StdoutLock<'static>>> = RefCell::new(BufWriter::new(stdout().lock())); } STDOUT.with(|w| f(&mut w.borrow_mut())) }