| Task: | Aristocracy |
| Sender: | Hävisin kalapelin |
| Submission time: | 2025-11-08 16:57:11 +0200 |
| Language: | Rust (2021) |
| Status: | READY |
| Result: | RUNTIME ERROR |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | details |
| #2 | ACCEPTED | 0.01 s | details |
| #3 | ACCEPTED | 0.01 s | details |
| #4 | ACCEPTED | 0.01 s | details |
| #5 | ACCEPTED | 0.02 s | details |
| #6 | RUNTIME ERROR | 0.02 s | details |
| #7 | RUNTIME ERROR | 0.02 s | details |
| #8 | RUNTIME ERROR | 0.02 s | details |
| #9 | RUNTIME ERROR | 0.03 s | details |
| #10 | TIME LIMIT EXCEEDED | -- | details |
| #11 | RUNTIME ERROR | 0.02 s | details |
| #12 | RUNTIME ERROR | 0.03 s | details |
| #13 | RUNTIME ERROR | 0.02 s | details |
| #14 | RUNTIME ERROR | 0.03 s | details |
| #15 | TIME LIMIT EXCEEDED | -- | details |
| #16 | TIME LIMIT EXCEEDED | -- | details |
| #17 | ACCEPTED | 0.01 s | details |
Code
use std::io;
use std::collections::HashMap;
const fn factorials() -> [i128; 10000] {
let mut out = [1i128; 10000];
let mut i: usize = 1;
while i < 10000 {
out[i] = out[i-1] * i as i128;
out[i] = out[i] % M;
i += 1;
}
out
}
const M: i128 = 1_000_000_007;
fn main() {
//dbg!(factorials());
let mut iter = io::stdin().lines();
let n = iter.next().unwrap().unwrap().trim().parse::<usize>().unwrap();
let mut titles = HashMap::<String, i128>::new();
for _ in 0..n {
let input = {
let input = iter.next().unwrap().unwrap();
input.split_whitespace().next().unwrap().to_string()
};
if let Some(val) = titles.get_mut(&input) {
*val += 1;
} else {
titles.insert(input, 1);
}
}
let mut inv = 1;
let mut q: i128 = 1;
for a in titles {
q *= factorials()[a.1 as usize];
q %= M;
}
let mut k;
while q != 1 {
k = M/q + 1;
q = (q*k) % M;
inv *= k;
inv %= M;
}
println!("{}", (inv*factorials()[n as usize]) % M);
}
Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 4 Uolevi 1 Maija 3 Uolevi 2 Maija 2 |
| correct output |
|---|
| 6 |
| user output |
|---|
| 6 |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 31 Eric 9 Charles 7 Sverker 2 Eric 10 ... |
| correct output |
|---|
| 541197645 |
| user output |
|---|
| 541197645 |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 19 Ivan 4 Feodor 1 Feodor 2 Dmitry 1 ... |
| correct output |
|---|
| 939302456 |
| user output |
|---|
| 939302456 |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 41 William 1 William 2 Henry 1 Stephen 1 ... |
| correct output |
|---|
| 520019025 |
| user output |
|---|
| 520019025 |
Test 5
Verdict: ACCEPTED
| input |
|---|
| 216 Peter 1 Linus 1 Cletus 1 Clement 1 ... |
| correct output |
|---|
| 200519221 |
| user output |
|---|
| 200519221 |
Test 6
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 A 1 A 2 A 3 A 4 ... |
| correct output |
|---|
| 1 |
| user output |
|---|
| (empty) |
Error:
thread 'main' panicked at input/code.rs:36:14: index out of bounds: the len is 10000 but the index is 100000 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Test 7
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 E 1 Y 1 Y 2 M 1 ... |
| correct output |
|---|
| 504127783 |
| user output |
|---|
| (empty) |
Error:
thread 'main' panicked at input/code.rs:46:25: index out of bounds: the len is 10000 but the index is 100000 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Test 8
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 Maija 1 Uolevi 1 Maija 2 Maija 3 ... |
| correct output |
|---|
| 328286172 |
| user output |
|---|
| (empty) |
Error:
thread 'main' panicked at input/code.rs:36:14: index out of bounds: the len is 10000 but the index is 50024 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Test 9
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 Maijx 1 Maije 1 Maijw 1 Maijp 1 ... |
| correct output |
|---|
| 178134668 |
| user output |
|---|
| (empty) |
Error:
thread 'main' panicked at input/code.rs:46:25: index out of bounds: the len is 10000 but the index is 100000 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Test 10
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 Bwvfj 1 Zmcpk 1 Jnmhz 1 Vcqtv 1 ... |
| correct output |
|---|
| 804665298 |
| user output |
|---|
| (empty) |
Test 11
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 A 947476077 A 209406366 A 64254608 A 370109404 ... |
| correct output |
|---|
| 1 |
| user output |
|---|
| (empty) |
Error:
thread 'main' panicked at input/code.rs:36:14: index out of bounds: the len is 10000 but the index is 100000 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Test 12
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 F 779918796 L 978222897 L 977989517 O 263870841 ... |
| correct output |
|---|
| 903086284 |
| user output |
|---|
| (empty) |
Error:
thread 'main' panicked at input/code.rs:46:25: index out of bounds: the len is 10000 but the index is 100000 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Test 13
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 Maija 968540665 Uolevi 869194539 Uolevi 530855688 Maija 232728327 ... |
| correct output |
|---|
| 271775549 |
| user output |
|---|
| (empty) |
Error:
thread 'main' panicked at input/code.rs:36:14: index out of bounds: the len is 10000 but the index is 50265 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Test 14
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 Uolevj 501874596 Uolevm 133829533 Uolevd 13322011 Uolevw 418508186 ... |
| correct output |
|---|
| 529945879 |
| user output |
|---|
| (empty) |
Error:
thread 'main' panicked at input/code.rs:46:25: index out of bounds: the len is 10000 but the index is 100000 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Test 15
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 Hamql 748803883 Mpfaf 709208011 Gegcd 685359815 Yvain 890816531 ... |
| correct output |
|---|
| 166192905 |
| user output |
|---|
| (empty) |
Test 16
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 Barmfsykcm 225712723 Xmvycwxssc 893904167 Wpetqrazdz 316367309 Eatxvkieif 111661228 ... |
| correct output |
|---|
| 457992974 |
| user output |
|---|
| (empty) |
Test 17
Verdict: ACCEPTED
| input |
|---|
| 1 Ltwgcnsajxaxhacysdjhrpzymwxaen... |
| correct output |
|---|
| 1 |
| user output |
|---|
| 1 |
