結果
問題 |
No.3211 NAND Oracle
|
ユーザー |
|
提出日時 | 2025-07-25 22:31:03 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 226 ms / 2,000 ms |
コード長 | 5,419 bytes |
コンパイル時間 | 10,219 ms |
コンパイル使用メモリ | 399,968 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-07-25 22:31:23 |
合計ジャッジ時間 | 15,039 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
use library::utils::input::Input; fn main() { let mut input = Input::new(); let (q, k) = input.pair::<usize,usize>(); if q>=6 { if k<5 { println!("No"); return; } else { println!("Yes"); println!("1 2\n2 3\n1 4\n1 5\n1 5"); for _ in 0..q-5 { println!("6 7") } } } else { if q==1 { if k>=2 { println!("Yes"); println!("1 2"); } else { println!("No"); } } else if q==2 { if k>=3 { println!("Yes"); println!("1 2"); println!("2 3"); } else { println!("No"); } } else if q==3 { if k >= 3 { println!("Yes"); println!("1 2"); println!("2 3"); println!("1 4"); } else { println!("No"); } } else if q==4 { if k >= 4 { println!("Yes"); println!("1 2"); println!("2 3"); println!("1 4"); println!("3 5"); } else { println!("No"); } } else if q==5 { if k >= 4 { println!("Yes"); println!("1 2"); println!("2 3"); println!("1 4"); println!("3 5"); println!("4 6"); } else { println!("No"); } } } } // ===== bundled library ===== pub mod library { pub mod utils { pub mod input { use std::str::{from_utf8, FromStr}; pub struct Input { buf: Vec<u8>, pos: usize, } impl Input { pub fn new() -> Self { Self { buf: Vec::new(), pos: 0 } } pub fn next<T: FromStr>(&mut self) -> T { while self.pos < self.buf.len() && self.buf[self.pos].is_ascii_whitespace() { self.pos += 1; } let start = self.pos; while self.pos < self.buf.len() && !self.buf[self.pos].is_ascii_whitespace() { self.pos += 1; } if start == self.pos { let mut input = String::new(); std::io::stdin() .read_line(&mut input) .expect("Failed to read line"); self.buf.clear(); self.buf.extend(input.as_bytes()); self.pos = 0; return self.next(); } from_utf8(&self.buf[start..self.pos]) .unwrap() .parse::<T>() .ok() .expect( &format!( "Failed to parse input: {}", from_utf8(& self.buf[start ..self.pos]).unwrap() ), ) } #[allow(non_snake_case)] pub fn vector<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.next()).collect() } pub fn graph( &mut self, n: usize, m: usize, is_one_way: bool, ) -> Vec<Vec<usize>> { let mut graph = vec![Vec::new(); n]; for _ in 0..m { let (u, v): (usize, usize) = self.pair(); graph[u - 1].push(v - 1); if !is_one_way { graph[v - 1].push(u - 1); } } graph } pub fn weighted_graph<T: Copy + FromStr>( &mut self, n: usize, m: usize, is_one_way: bool, is_one_based: bool, ) -> Vec<Vec<(usize, T)>> { let mut graph = vec![Vec::new(); n]; for _ in 0..m { let (u, v, w): (usize, usize, T) = self.triple(); let u = if is_one_based { u - 1 } else { u }; let v = if is_one_based { v - 1 } else { v }; graph[u].push((v, w)); if !is_one_way { graph[v].push((u, w)); } } graph } pub fn pair<T: FromStr, U: FromStr>(&mut self) -> (T, U) { (self.next(), self.next()) } pub fn triple<T: FromStr, U: FromStr, V: FromStr>( &mut self, ) -> (T, U, V) { (self.next(), self.next(), self.next()) } } } } }