結果

問題 No.5020 Averaging
ユーザー akidaiakidai
提出日時 2024-02-25 13:40:41
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 2,055 bytes
コンパイル時間 1,374 ms
コンパイル使用メモリ 180,000 KB
実行使用メモリ 6,676 KB
スコア 24,229,346
最終ジャッジ日時 2024-02-25 13:40:44
合計ジャッジ時間 3,107 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 1 ms
6,676 KB
testcase_08 AC 1 ms
6,676 KB
testcase_09 AC 1 ms
6,676 KB
testcase_10 AC 1 ms
6,676 KB
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 1 ms
6,676 KB
testcase_13 AC 1 ms
6,676 KB
testcase_14 AC 1 ms
6,676 KB
testcase_15 AC 1 ms
6,676 KB
testcase_16 AC 1 ms
6,676 KB
testcase_17 AC 1 ms
6,676 KB
testcase_18 AC 1 ms
6,676 KB
testcase_19 AC 0 ms
6,676 KB
testcase_20 AC 1 ms
6,676 KB
testcase_21 AC 1 ms
6,676 KB
testcase_22 AC 1 ms
6,676 KB
testcase_23 AC 1 ms
6,676 KB
testcase_24 AC 1 ms
6,676 KB
testcase_25 AC 1 ms
6,676 KB
testcase_26 AC 1 ms
6,676 KB
testcase_27 AC 1 ms
6,676 KB
testcase_28 AC 1 ms
6,676 KB
testcase_29 AC 1 ms
6,676 KB
testcase_30 AC 1 ms
6,676 KB
testcase_31 AC 1 ms
6,676 KB
testcase_32 AC 1 ms
6,676 KB
testcase_33 AC 1 ms
6,676 KB
testcase_34 AC 1 ms
6,676 KB
testcase_35 AC 1 ms
6,676 KB
testcase_36 AC 1 ms
6,676 KB
testcase_37 AC 1 ms
6,676 KB
testcase_38 AC 1 ms
6,676 KB
testcase_39 AC 1 ms
6,676 KB
testcase_40 AC 1 ms
6,676 KB
testcase_41 AC 1 ms
6,676 KB
testcase_42 AC 1 ms
6,676 KB
testcase_43 AC 1 ms
6,676 KB
testcase_44 AC 1 ms
6,676 KB
testcase_45 AC 1 ms
6,676 KB
testcase_46 AC 1 ms
6,676 KB
testcase_47 AC 1 ms
6,676 KB
testcase_48 AC 1 ms
6,676 KB
testcase_49 AC 1 ms
6,676 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `min`
 --> Main.rs:1:21
  |
1 | use std::cmp::{max, min};
  |                     ^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: 1 warning emitted

ソースコード

diff #

use std::cmp::{max, min};
use std::io;



fn main() {
    let mut buffer = String::new();
    io::stdin().read_line(&mut buffer).unwrap();
    let n: usize = buffer.trim().parse().unwrap();
    let mut cards = vec![];
    for _ in 0..n {
        let mut buffer = String::new();
        io::stdin().read_line(&mut buffer).unwrap();
        let mut iter = buffer.trim().split_whitespace();
        let x: i64 = iter.next().unwrap().parse().unwrap();
        let y: i64 = iter.next().unwrap().parse().unwrap();
        cards.push((x, y));
    }

    let target = 10_i64.pow(17) * 5;
    let mut ans = vec![];
    for i in 0..50 {
        let mut cur_diff = max((cards[0].0 - target).abs(), (cards[0].1 - target).abs());
        let mut tmp = (n, n);
        for p in 1..n {
            let new_card_0 = ((cards[p].0 + cards[0].0) / 2, (cards[p].1 + cards[0].1) / 2);
            let new_diff = max((new_card_0.0 - target).abs(), (new_card_0.1 - target).abs());
            if new_diff < cur_diff {
                cur_diff = new_diff;
                tmp = (0, p);
            }
        }
        if i < 49 {
            for p in 1..n {
                for q in p + 1..n {
                    let new_card = ((cards[p].0 + cards[q].0) / 2, (cards[p].1 + cards[q].1) / 2);

                    let new_card_0 = ((cards[0].0 + new_card.0) / 2, (cards[0].1 + new_card.1) / 2);
                    let new_diff = max((new_card_0.0 - target).abs(), (new_card_0.1 - target).abs());
                    if new_diff < cur_diff {
                        cur_diff = new_diff;
                        tmp = (p, q);
                    }
                }
            }
        }
        if tmp == (n, n) {
            break;
        }
        let new_card = ((cards[tmp.0].0 + cards[tmp.1].0) / 2, (cards[tmp.0].1 + cards[tmp.1].1) / 2);
        cards[tmp.0] = new_card;
        cards[tmp.1] = new_card;
        ans.push(tmp);
    }
    println!("{}", ans.len());
    for a in ans {
        println!("{} {}", a.0 + 1, a.1 + 1);
    }
    // eprintln!("{:?}", cards);
}
0