結果
問題 | No.2567 A_1 > A_2 > ... > A_N |
ユーザー | ikd |
提出日時 | 2023-12-02 16:48:14 |
言語 | Rust (1.77.0 + proconio) |
結果 |
RE
|
実行時間 | - |
コード長 | 4,126 bytes |
コンパイル時間 | 11,408 ms |
コンパイル使用メモリ | 383,848 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-26 20:44:30 |
合計ジャッジ時間 | 13,647 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | AC | 133 ms
5,376 KB |
testcase_07 | AC | 132 ms
5,376 KB |
testcase_08 | AC | 131 ms
5,376 KB |
testcase_09 | AC | 132 ms
5,376 KB |
testcase_10 | AC | 137 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 1 ms
5,376 KB |
testcase_13 | AC | 1 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 1 ms
5,376 KB |
ソースコード
use scanner::Scanner; use std::io; fn main() { let mut scanner = Scanner::from(io::stdin().lock()); let t = scan!(usize, <~ scanner); for _ in 0..t { let (n, x) = scan!((usize, usize), <~ scanner); if n * (n + 1) / 2 > x { println!("-1"); continue; } let mut acc = 0; let mut ans = Vec::new(); for i in 0..n { let mut y = 2_000_000_000; let mut ng = 0; while y - ng > 1 { let z = (y + ng) / 2; if z > n - i - 1 { // (z - 1) + (z - 2) + ... + (z - (n - i - 1)) let rest = ((z - 1) + (z - (n - i - 1))) * (n - i - 1) / 2; if x.saturating_sub(acc + z) <= rest { y = z; } else { ng = z; } } else { ng = z; } } ans.push(y); acc += y; } for i in 1..n { assert!(ans[i - 1] > ans[i]); } for i in 0..n { print!("{}", ans[i]); if i + 1 < n { print!(" "); } else { print!("\n"); } } } } // ✂ --- scanner --- ✂ #[allow(unused)] mod scanner { use std::fmt; use std::io; use std::str; pub struct Scanner<R> { r: R, l: String, i: usize, } impl<R> Scanner<R> where R: io::BufRead, { pub fn new(reader: R) -> Self { Self { r: reader, l: String::new(), i: 0, } } pub fn scan<T>(&mut self) -> T where T: str::FromStr, T::Err: fmt::Debug, { self.skip_blanks(); assert!(self.i < self.l.len()); // remain some character assert_ne!(&self.l[self.i..=self.i], " "); let rest = &self.l[self.i..]; let len = rest .find(|ch| char::is_ascii_whitespace(&ch)) .unwrap_or_else(|| rest.len()); // parse self.l[self.i..(self.i + len)] let val = rest[..len] .parse() .unwrap_or_else(|e| panic!("{:?}, attempt to read `{}`", e, rest)); self.i += len; val } pub fn scan_vec<T>(&mut self, n: usize) -> Vec<T> where T: str::FromStr, T::Err: fmt::Debug, { (0..n).map(|_| self.scan()).collect::<Vec<_>>() } fn skip_blanks(&mut self) { loop { match self.l[self.i..].find(|ch| !char::is_ascii_whitespace(&ch)) { Some(j) => { self.i += j; break; } None => { self.l.clear(); // clear buffer let num_bytes = self .r .read_line(&mut self.l) .unwrap_or_else(|_| panic!("invalid UTF-8")); assert!(num_bytes > 0, "reached EOF :("); self.i = 0; } } } } } impl<'a> From<&'a str> for Scanner<&'a [u8]> { fn from(s: &'a str) -> Self { Self::new(s.as_bytes()) } } impl<'a> From<io::StdinLock<'a>> for Scanner<io::BufReader<io::StdinLock<'a>>> { fn from(stdin: io::StdinLock<'a>) -> Self { Self::new(io::BufReader::new(stdin)) } } #[macro_export] macro_rules! scan { (( $($t: ty),+ ), <~ $scanner: expr) => { ( $(scan!($t, <~ $scanner)),+ ) }; ([ $t: tt; $n: expr ], <~ $scanner: expr) => { (0..$n).map(|_| scan!($t, <~ $scanner)).collect::<Vec<_>>() }; ($t: ty, <~ $scanner: expr) => { $scanner.scan::<$t>() }; } } // ✂ --- scanner --- ✂