結果
問題 | No.5020 Averaging |
ユーザー | akidai |
提出日時 | 2024-02-25 13:23:22 |
言語 | Rust (1.83.0 + proconio) |
結果 |
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 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 50 |
コンパイルメッセージ
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
ソースコード
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); } }