Submission details
Task:Lucky prefixes
Sender:freefoodfreepoints
Submission time:2025-11-08 14:50:58 +0200
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#10.00 sdetails
#20.04 sdetails
#30.00 sdetails
#40.00 sdetails
#50.11 sdetails
#60.00 sdetails
#70.01 sdetails
#80.05 sdetails
#90.11 sdetails
#100.00 sdetails
#110.00 sdetails
#120.11 sdetails
#130.00 sdetails
#140.01 sdetails
#150.05 sdetails
#160.11 sdetails

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:

input
6 4
3 -2 1 5 6 1
2 1 3
2 2 3
1 3 -2
...

correct output
YES
NO
NO

user output
360

Feedback: Output is shorter than expected

Test 2

Verdict:

input
200000 200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
NO
NO
NO
NO
NO
...

user output
637894743

Feedback: Output is shorter than expected

Test 3

Verdict:

input
10 10
629447384 -729045992 811583872...

correct output
YES
NO
NO
NO
NO
...

user output
907200

Feedback: Output is shorter than expected

Test 4

Verdict:

input
1 200000
629447384
1 1 670017180
1 1 826751744
1 1 -804919168
...

correct output
NO
NO
NO
YES
YES
...

user output
1

Feedback: Output is shorter than expected

Test 5

Verdict:

input
200000 200000
629447384 -729045992 811583872...

correct output
NO
NO
NO
NO
NO
...

user output
841700673

Feedback: Output is shorter than expected

Test 6

Verdict:

input
1000 200000
629447384 -729045992 811583872...

correct output
NO
NO
NO
NO
NO
...

user output
640753664

Feedback: Output is shorter than expected

Test 7

Verdict:

input
10000 200000
629447384 -729045992 811583872...

correct output
NO
NO
NO
NO
NO
...

user output
333236525

Feedback: Output is shorter than expected

Test 8

Verdict:

input
100000 200000
629447384 -729045992 811583872...

correct output
NO
NO
NO
NO
NO
...

user output
286267582

Feedback: Output is shorter than expected

Test 9

Verdict:

input
200000 200000
629447384 -729045992 811583872...

correct output
NO
NO
NO
NO
NO
...

user output
841700673

Feedback: Output is shorter than expected

Test 10

Verdict:

input
10 10
629447384 -729045992 811583872...

correct output
YES
NO
NO
NO
NO
...

user output
907200

Feedback: Output is shorter than expected

Test 11

Verdict:

input
1 200000
629447384
1 1 670017180
1 1 826751744
1 1 -804919168
...

correct output
NO
NO
NO
YES
YES
...

user output
1

Feedback: Output is shorter than expected

Test 12

Verdict:

input
200000 200000
629447384 -729045992 811583872...

correct output
NO
NO
NO
NO
NO
...

user output
841700673

Feedback: Output is shorter than expected

Test 13

Verdict:

input
1000 200000
629447384 -729045992 811583872...

correct output
NO
NO
NO
NO
NO
...

user output
640753664

Feedback: Output is shorter than expected

Test 14

Verdict:

input
10000 200000
629447384 -729045992 811583872...

correct output
NO
NO
NO
NO
NO
...

user output
333236525

Feedback: Output is shorter than expected

Test 15

Verdict:

input
100000 200000
629447384 -729045992 811583872...

correct output
NO
NO
NO
NO
NO
...

user output
286267582

Feedback: Output is shorter than expected

Test 16

Verdict:

input
200000 200000
629447384 -729045992 811583872...

correct output
NO
NO
NO
NO
NO
...

user output
841700673

Feedback: Output is shorter than expected