結果

問題 No.2355 Unhappy Back Dance
ユーザー koba-e964koba-e964
提出日時 2023-06-16 23:15:49
言語 Rust
(1.77.0)
結果
RE  
実行時間 -
コード長 2,760 bytes
コンパイル時間 1,175 ms
コンパイル使用メモリ 161,004 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 22:12:20
合計ジャッジ時間 6,526 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 0 ms
4,380 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 142 ms
4,380 KB
testcase_07 AC 143 ms
4,380 KB
testcase_08 AC 142 ms
4,376 KB
testcase_09 AC 26 ms
4,376 KB
testcase_10 AC 110 ms
4,376 KB
testcase_11 AC 126 ms
4,376 KB
testcase_12 AC 166 ms
4,380 KB
testcase_13 AC 161 ms
4,380 KB
testcase_14 AC 112 ms
4,376 KB
testcase_15 RE -
testcase_16 AC 249 ms
4,376 KB
testcase_17 AC 251 ms
4,376 KB
testcase_18 AC 250 ms
4,380 KB
testcase_19 AC 248 ms
4,380 KB
testcase_20 AC 248 ms
4,376 KB
testcase_21 AC 99 ms
4,376 KB
testcase_22 AC 17 ms
4,376 KB
testcase_23 AC 19 ms
4,380 KB
testcase_24 AC 224 ms
4,376 KB
testcase_25 AC 117 ms
4,376 KB
testcase_26 AC 118 ms
4,376 KB
testcase_27 AC 102 ms
4,380 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 205 ms
4,380 KB
testcase_31 AC 147 ms
4,376 KB
testcase_32 AC 14 ms
4,376 KB
testcase_33 AC 82 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 3 ms
4,376 KB
testcase_36 AC 101 ms
4,380 KB
testcase_37 AC 53 ms
4,380 KB
testcase_38 AC 64 ms
4,376 KB
testcase_39 AC 50 ms
4,380 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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

trait Change { fn chmax(&mut self, x: Self); fn chmin(&mut self, x: Self); }
impl<T: PartialOrd> Change for T {
    fn chmax(&mut self, x: T) { if *self < x { *self = x; } }
    fn chmin(&mut self, x: T) { if *self > x { *self = x; } }
}

type Coord = i64; // 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: [(i64, i64); n],
    }
    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