結果
問題 |
No.1041 直線大学
|
ユーザー |
|
提出日時 | 2020-05-29 18:17:07 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,508 bytes |
コンパイル時間 | 13,243 ms |
コンパイル使用メモリ | 379,372 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-16 08:04:35 |
合計ジャッジ時間 | 14,295 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
ソースコード
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> { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() } fn main() { let n: usize = read(); let ps = (0..n).map(|_| { let input:Vec<usize> = read_vec(); (input[0], input[1]) }).collect::<Vec<(usize,usize)>>(); println!("{}", no1041(ps)); } fn no1041(ps:Vec<(usize,usize)>) -> usize { let in_line = |(x1,y1):&(usize,usize),(x2,y2):&(usize,usize),(x3,y3):&(usize,usize)| -> bool { let x1 = *x1 as f64; let y1 = *y1 as f64; let x2 = *x2 as f64; let y2 = *y2 as f64; let x3 = *x3 as f64; let y3 = *y3 as f64; if x2-x1 == 0.0 && x3-x1 == 0.0 || y2-y1 == 0.0 && y3-y1 == 0.0 { true } else if x2-x1 != 0.0 && x3-x1 != 0.0 { (y2-y1)/(x2-x1) == (y3-y1)/(x3-x1) } else { false } }; let mut counter:Vec<Vec<usize>> = vec![vec![2;ps.len()];ps.len()]; for i in 0..ps.len()-2 { for j in i+1..ps.len()-1 { counter[i][j] = 2; for k in j+1..ps.len() { if in_line(&ps[i],&ps[j],&ps[k]) { counter[i][j] += 1; } } } } let mut max = 0; for a in counter { for b in a { if b > max { max = b; } } } max }