結果

問題 No.2355 Unhappy Back Dance
ユーザー koba-e964koba-e964
提出日時 2023-06-16 23:22:31
言語 Rust
(1.77.0)
結果
AC  
実行時間 405 ms / 6,000 ms
コード長 2,297 bytes
コンパイル時間 1,207 ms
コンパイル使用メモリ 157,696 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 22:23:23
合計ジャッジ時間 8,532 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 228 ms
4,380 KB
testcase_07 AC 228 ms
4,380 KB
testcase_08 AC 225 ms
4,380 KB
testcase_09 AC 34 ms
4,380 KB
testcase_10 AC 176 ms
4,376 KB
testcase_11 AC 207 ms
4,376 KB
testcase_12 AC 265 ms
4,380 KB
testcase_13 AC 259 ms
4,376 KB
testcase_14 AC 185 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 402 ms
4,380 KB
testcase_17 AC 405 ms
4,376 KB
testcase_18 AC 405 ms
4,376 KB
testcase_19 AC 403 ms
4,376 KB
testcase_20 AC 399 ms
4,376 KB
testcase_21 AC 161 ms
4,376 KB
testcase_22 AC 28 ms
4,376 KB
testcase_23 AC 30 ms
4,376 KB
testcase_24 AC 359 ms
4,380 KB
testcase_25 AC 188 ms
4,376 KB
testcase_26 AC 188 ms
4,376 KB
testcase_27 AC 160 ms
4,376 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 8 ms
4,380 KB
testcase_30 AC 326 ms
4,376 KB
testcase_31 AC 234 ms
4,380 KB
testcase_32 AC 21 ms
4,380 KB
testcase_33 AC 129 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 4 ms
4,376 KB
testcase_36 AC 161 ms
4,376 KB
testcase_37 AC 83 ms
4,376 KB
testcase_38 AC 104 ms
4,380 KB
testcase_39 AC 80 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::*;
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

type Coord = i128; // the type of coordinates

fn half((x, y, _): (Coord, Coord, i32)) -> i32 {
    assert_ne!((x, y), (0, 0));
    if y >= 0 {
        if x > 0 || y > 0 {
            1
        } else {
            2
        }
    } else {
        2
    }
}

// arg sort
// Verified by: https://yukicoder.me/submissions/706856
fn arg_sort(xy: &mut [(Coord, Coord, i32)]) {
    xy.sort_unstable_by(|&a, &b| {
        half(a).cmp(&half(b)).then_with(
            || 0.cmp(&(a.0 * b.1 - a.1 * b.0))
                .then_with(|| a.2.cmp(&b.2)))
    });
}

fn main() {
    input! {
        n: usize,
        a: [(i128, i128); n],
    }
    if n == 1 {
        println!("0");
        return;
    }
    let mut ans = 0;
    for i in 0..n {
        let (xi, yi) = a[i];
        let mut b = vec![];
        for j in 0..n {
            if i != j {
                b.push((a[j].0 - xi, a[j].1 - yi, j as i32));
            }
        }
        arg_sort(&mut b);
        for i in 0..b.len() - 1 {
            let a = b[i];
            let b = b[i + 1];
            if half(a).cmp(&half(b)).then_with(
                || 0.cmp(&(a.0 * b.1 - a.1 * b.0))) == Ordering::Equal {
                ans += 1;
                break;
            }
        }
    }
    println!("{}", ans);
}
0