結果

問題 No.5020 Averaging
ユーザー akidaiakidai
提出日時 2024-02-25 13:23:22
言語 Rust
(1.77.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,703 bytes
コンパイル時間 1,585 ms
コンパイル使用メモリ 184,316 KB
実行使用メモリ 6,676 KB
スコア 15,796,941
最終ジャッジ日時 2024-02-25 13:23:25
合計ジャッジ時間 3,552 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 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 2 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 1 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 2 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 2 ms
6,676 KB
testcase_39 AC 1 ms
6,676 KB
testcase_40 AC 2 ms
6,676 KB
testcase_41 AC 1 ms
6,676 KB
testcase_42 AC 2 ms
6,676 KB
testcase_43 AC 1 ms
6,676 KB
testcase_44 AC 1 ms
6,676 KB
testcase_45 AC 2 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: unnecessary parentheses around `if` condition
  --> Main.rs:29:19
   |
29 |                 if(min_diff > new_diff - prev_diff) {
   |                   ^                               ^
   |
   = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
   |
29 -                 if(min_diff > new_diff - prev_diff) {
29 +                 if min_diff > new_diff - prev_diff {
   |

warning: unused variable: `i`
  --> Main.rs:20:9
   |
20 |     for i in 0..50 {
   |         ^ help: if this is intentional, prefix it with an underscore: `_i`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 3 warnings 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 plan = 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();
        plan.push((x, y));
    }

    let target = 10_i64.pow(17) * 5;
    let mut ans = vec![];
    for i in 0..50 {
        let mut min_diff = 0;
        let mut tmp = (n, n);
        for p in 0..n {
            for q in p + 1..n {
                let prev_diff = max((plan[p].0 - target).abs(), (plan[q].0 - target).abs()) + max((plan[p].1 - target).abs(), (plan[q].1 - target).abs());
                let new_0 = (plan[p].0 + plan[q].0) / 2;
                let new_1 = (plan[p].1 + plan[q].1) / 2;
                let new_diff = (new_0 - target).abs() + (new_1 - target).abs();
                if(min_diff > new_diff - prev_diff) {
                    min_diff = new_diff - prev_diff;
                    tmp = (p, q);
                }
            }
        }
        if min_diff == 0 {
            break;
        }
        plan[tmp.0].0 = (plan[tmp.0].0 + plan[tmp.1].0) / 2;
        plan[tmp.1].0 = (plan[tmp.0].0 + plan[tmp.1].0) / 2;
        plan[tmp.0].1 = (plan[tmp.0].1 + plan[tmp.1].1) / 2;
        plan[tmp.1].1 = (plan[tmp.0].1 + plan[tmp.1].1) / 2;
        ans.push(tmp);
    }
    println!("{}", ans.len());
    for a in ans {
        println!("{} {}", a.0 + 1, a.1 + 1);
    }
}
0