| Task: | Aristocracy |
| Sender: | freefoodfreepoints |
| Submission time: | 2025-11-08 14:52:32 +0200 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | details |
| #2 | ACCEPTED | 0.00 s | details |
| #3 | ACCEPTED | 0.00 s | details |
| #4 | ACCEPTED | 0.00 s | details |
| #5 | ACCEPTED | 0.00 s | details |
| #6 | ACCEPTED | 0.02 s | details |
| #7 | ACCEPTED | 0.02 s | details |
| #8 | ACCEPTED | 0.02 s | details |
| #9 | ACCEPTED | 0.02 s | details |
| #10 | ACCEPTED | 0.06 s | details |
| #11 | ACCEPTED | 0.02 s | details |
| #12 | ACCEPTED | 0.03 s | details |
| #13 | ACCEPTED | 0.03 s | details |
| #14 | ACCEPTED | 0.03 s | details |
| #15 | ACCEPTED | 0.06 s | details |
| #16 | ACCEPTED | 0.06 s | details |
| #17 | ACCEPTED | 0.01 s | details |
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define til(n) for(ll i = 0; i < n; i++)
constexpr ll mod = 1e9+7;
ll euclid(ll a, ll b, ll& x, ll& y){
if (!b) return x=1,y=0,a;
ll d = euclid(b,a%b,y,x);
return y-=a/b * x, d;
}
struct Mod {
ll x;
Mod(ll xx) : x(xx) {}
Mod operator* (Mod b) { return Mod((x * b.x) % mod); }
Mod operator/ (Mod b) { return *this * invert(b); }
Mod invert(Mod a) {
ll x,y,g = euclid(a.x,mod,x,y);
assert (g==1);
return Mod((x+mod) % mod);
}
};
auto fac(ll n) {
auto total = Mod(1);
til(n) {
total = (total * (i + 1));
}
return total;
}
int main() {
cin.tie(0)->sync_with_stdio(false);
cout.tie(0)->sync_with_stdio(false);
ll n;
unordered_map<string,ll> m;
cin >> n;
til(n) {
string s;
ll _;
cin >> s >> _;
m[s]++;
}
auto total = fac(n);
for (auto [k, v] : m) {
total = total / fac(v);
}
cout << total.x << '\n';
}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: ACCEPTED
| input |
|---|
| 100000 A 1 A 2 A 3 A 4 ... |
| correct output |
|---|
| 1 |
| user output |
|---|
| 1 |
Test 7
Verdict: ACCEPTED
| input |
|---|
| 100000 E 1 Y 1 Y 2 M 1 ... |
| correct output |
|---|
| 504127783 |
| user output |
|---|
| 504127783 |
Test 8
Verdict: ACCEPTED
| input |
|---|
| 100000 Maija 1 Uolevi 1 Maija 2 Maija 3 ... |
| correct output |
|---|
| 328286172 |
| user output |
|---|
| 328286172 |
Test 9
Verdict: ACCEPTED
| input |
|---|
| 100000 Maijx 1 Maije 1 Maijw 1 Maijp 1 ... |
| correct output |
|---|
| 178134668 |
| user output |
|---|
| 178134668 |
Test 10
Verdict: ACCEPTED
| input |
|---|
| 100000 Bwvfj 1 Zmcpk 1 Jnmhz 1 Vcqtv 1 ... |
| correct output |
|---|
| 804665298 |
| user output |
|---|
| 804665298 |
Test 11
Verdict: ACCEPTED
| input |
|---|
| 100000 A 947476077 A 209406366 A 64254608 A 370109404 ... |
| correct output |
|---|
| 1 |
| user output |
|---|
| 1 |
Test 12
Verdict: ACCEPTED
| input |
|---|
| 100000 F 779918796 L 978222897 L 977989517 O 263870841 ... |
| correct output |
|---|
| 903086284 |
| user output |
|---|
| 903086284 |
Test 13
Verdict: ACCEPTED
| input |
|---|
| 100000 Maija 968540665 Uolevi 869194539 Uolevi 530855688 Maija 232728327 ... |
| correct output |
|---|
| 271775549 |
| user output |
|---|
| 271775549 |
Test 14
Verdict: ACCEPTED
| input |
|---|
| 100000 Uolevj 501874596 Uolevm 133829533 Uolevd 13322011 Uolevw 418508186 ... |
| correct output |
|---|
| 529945879 |
| user output |
|---|
| 529945879 |
Test 15
Verdict: ACCEPTED
| input |
|---|
| 100000 Hamql 748803883 Mpfaf 709208011 Gegcd 685359815 Yvain 890816531 ... |
| correct output |
|---|
| 166192905 |
| user output |
|---|
| 166192905 |
Test 16
Verdict: ACCEPTED
| input |
|---|
| 100000 Barmfsykcm 225712723 Xmvycwxssc 893904167 Wpetqrazdz 316367309 Eatxvkieif 111661228 ... |
| correct output |
|---|
| 457992974 |
| user output |
|---|
| 457992974 |
Test 17
Verdict: ACCEPTED
| input |
|---|
| 1 Ltwgcnsajxaxhacysdjhrpzymwxaen... |
| correct output |
|---|
| 1 |
| user output |
|---|
| 1 |
