結果

問題 No.1041 直線大学
ユーザー iwotiwot
提出日時 2020-05-29 18:17:07
言語 Rust
(1.77.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,508 bytes
コンパイル時間 13,416 ms
コンパイル使用メモリ 377,104 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 00:16:24
合計ジャッジ時間 12,028 ms
ジャッジサーバーID
(参考情報)
judge2 / 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 0 ms
5,376 KB
testcase_04 AC 0 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 0 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 0 ms
5,376 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 0 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
testcase_36 AC 1 ms
5,376 KB
testcase_37 AC 1 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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
}

0