結果
| 問題 |
No.3128 Isosceles Triangle
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-25 22:05:04 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 115 ms / 2,500 ms |
| コード長 | 3,381 bytes |
| コンパイル時間 | 12,836 ms |
| コンパイル使用メモリ | 401,828 KB |
| 実行使用メモリ | 23,660 KB |
| 最終ジャッジ日時 | 2025-04-25 22:05:38 |
| 合計ジャッジ時間 | 15,725 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
#![allow(unused_imports)]
#![allow(dead_code)]
use std::cell::RefCell;
use std::cmp::{Ordering, Reverse};
use std::collections::btree_map::Entry as BTreeMapEntry;
use std::collections::hash_map::{Entry as HashMapEntry, Entry};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::fmt::{Debug, Display, Formatter, Write};
use std::hash::Hash;
use std::io::{stdin, BufRead, BufWriter, Write as _};
use std::ops::{Bound, ControlFlow, Range, RangeBounds, RangeInclusive};
use std::rc::Rc;
use std::str::FromStr;
use std::sync::atomic;
use std::sync::atomic::AtomicUsize;
use std::thread::LocalKey;
use std::time::{Duration, Instant};
use std::{array, convert, io, iter, mem, ptr};
pub fn solve(InputObject { cin }: InputObject) {
let n = cin.next();
let a: Vec<usize> = cin.next_vec(n);
let mut a_count = BTreeMap::new();
for a in a {
*a_count.entry(a).or_insert(0usize) += 1;
}
let a = a_count.into_iter().collect::<Vec<_>>();
let mut lim = 0;
let mut count_sum = 0;
let mut ans = 0;
for &(length, count) in a.iter() {
if count < 2 {
continue;
}
while lim < a.len() && a[lim].0 < length * 2 {
count_sum += a[lim].1;
lim += 1;
}
ans += count * (count - 1) / 2 * (count_sum - count);
}
println!("{}", ans);
}
pub struct InputObject<'a> {
cin: &'a mut ConsoleInput,
}
fn input(cin: &mut ConsoleInput) -> InputObject {
InputObject { cin }
}
pub fn main() {
let mut cin = ConsoleInput::new();
let input = input(&mut cin);
solve(input);
}
// libraries below
pub struct ConsoleInput {
queue: VecDeque<String>,
}
pub trait Input {
fn next<T: FromStr>(&mut self) -> T;
fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
(0..n).map(|_| self.next()).collect()
}
}
pub trait Output {
fn write(&self);
}
impl Output for () {
fn write(&self) {}
}
impl Input for ConsoleInput {
fn next<T: FromStr>(&mut self) -> T {
match self.read().parse() {
Ok(value) => value,
_ => panic!("parse error"),
}
}
}
impl ConsoleInput {
fn new() -> Self {
Self {
queue: VecDeque::new(),
}
}
fn read(&mut self) -> String {
loop {
if let Some(s) = self.queue.pop_front() {
return s;
}
let mut s = String::new();
stdin().read_line(&mut s).expect("failed to read");
for s in s.split_ascii_whitespace() {
self.queue.push_back(String::from(s));
}
}
}
}
fn binary_search(range: Range<usize>, f: impl Fn(usize) -> Ordering) -> Result<usize, usize> {
let mut start = range.start;
let mut len = range.len();
if len == 0 {
return Err(0);
}
while len > 1 {
let half = len / 2;
let mid = start + half;
if f(mid) != Ordering::Greater {
start = mid;
}
len -= half;
}
match f(start) {
Ordering::Equal => Ok(start),
Ordering::Less => Err(start + 1),
Ordering::Greater => Err(start),
}
}
fn all_bits() -> impl Iterator<Item = impl Iterator<Item = (usize, bool)>> {
(0usize..).map(|i| (0usize..).map(move |j| (j, (i >> j) & 1 != 0)))
}
#[cfg(test)]
mod tests;