結果
問題 |
No.118 門松列(2)
|
ユーザー |
|
提出日時 | 2020-04-03 10:48:59 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 761 bytes |
コンパイル時間 | 15,189 ms |
コンパイル使用メモリ | 390,480 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-28 17:44:58 |
合計ジャッジ時間 | 11,992 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
use std::io::*; fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let n: usize = itr.next().unwrap().parse().unwrap(); let a: Vec<usize> = (0..n) .map(|_| itr.next().unwrap().parse().unwrap()) .collect(); // n C 3 - let mut cnt: Vec<usize> = vec![0; 100010]; for i in 0..n { cnt[a[i]] += 1; } let mut ans = n * (n - 1) * (n - 2) / 3 / 2; for i in 0..100005 { if cnt[i] >= 3 { ans -= cnt[i] * (cnt[i] - 1) * (cnt[i] - 2) / 3 / 2; } if cnt[i] >= 2 { ans -= cnt[i] * (cnt[i] - 1) / 2 * (n - cnt[i]); } } println!("{}", ans % 1_000_000_007); }