結果
| 問題 |
No.5020 Averaging
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-11 14:31:26 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 1,000 ms |
| コード長 | 1,960 bytes |
| コンパイル時間 | 14,397 ms |
| コンパイル使用メモリ | 402,576 KB |
| 実行使用メモリ | 7,720 KB |
| スコア | 18,728,251 |
| 最終ジャッジ日時 | 2025-04-11 14:31:43 |
| 合計ジャッジ時間 | 14,640 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 50 |
コンパイルメッセージ
warning: unused import: `std::cell::OnceCell`
--> src/main.rs:3:5
|
3 | use std::cell::OnceCell;
| ^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: unused imports: `Bytes` and `Usize1`
--> src/main.rs:5:24
|
5 | use proconio::marker::{Bytes, Usize1};
| ^^^^^ ^^^^^^
warning: function `card_error_sum` is never used
--> src/main.rs:61:4
|
61 | fn card_error_sum(u: (u64, u64)) -> u64 {
| ^^^^^^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
ソースコード
// -*- coding:utf-8-unix -*-
use std::cell::OnceCell;
use proconio::marker::{Bytes, Usize1};
use proconio::{fastout, input};
const TARGET: u64 = 500_000_000_000_000_000;
const MINV: u64 = 100_000_000_000_000_000;
const TARGET_ADJ: u64 = TARGET - MINV;
const OP_NUM: usize = 50;
#[fastout]
fn main() {
let _ = get_time();
input! {
n: usize,
mut ab: [(u64, u64); n],
}
for x in &mut ab {
x.0 -= MINV;
x.1 -= MINV;
}
let mut ans = Vec::new();
for _ in 0..OP_NUM {
let mut best_v = 0;
let mut best_score = u64::MAX;
for v in 1..n {
let ab_new = card_avg(ab[0], ab[v]);
let new_score = card_error_max(ab_new);
if new_score < best_score {
best_score = new_score;
best_v = v;
}
}
ans.push((0, best_v));
ab[0] = card_avg(ab[0], ab[best_v]);
}
println!("{}", ans.len());
for &(u, v) in &ans {
println!("{} {}", u + 1, v + 1);
}
// eprintln!("# Metric end_time float {}", get_time());
// std::process::exit(0);
}
fn card_avg(u: (u64, u64), v: (u64, u64)) -> (u64, u64) {
((u.0 + v.0) / 2, (u.1 + v.1) / 2)
}
fn card_error_max(u: (u64, u64)) -> u64 {
(u.0.abs_diff(TARGET_ADJ)).max(u.1.abs_diff(TARGET_ADJ))
}
fn card_error_sum(u: (u64, u64)) -> u64 {
(u.0.abs_diff(TARGET_ADJ)) + (u.1.abs_diff(TARGET_ADJ))
}
//
// MARK: Time Measurement
//
pub fn get_time() -> f64 {
static mut STIME: f64 = -1.0;
let t = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap();
let ms = t.as_secs() as f64 + t.subsec_nanos() as f64 * 1e-9;
unsafe {
if STIME < 0.0 {
STIME = ms;
}
ms - STIME
}
}
#[allow(unused)]
#[cfg(debug_assertions)]
const TIME_LIMIT: f64 = 10.;
#[allow(unused)]
#[cfg(not(debug_assertions))]
const TIME_LIMIT: f64 = 2.9;