QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#507114#5746. DAG GenerationchimeraRE 0ms4572kbC++141.9kb2024-08-06 11:05:112024-08-06 11:05:12

Judging History

你现在查看的是最新测评结果

  • [2024-08-06 11:05:12]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:4572kb
  • [2024-08-06 11:05:11]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long

const ll MOD = 1000000009;

// idea: isolate one vertex at a time.
// what is the probability that vertex has the exact same set of connections?

// operation: add it to a random point in sequence and add edges in and out randomly.

// P(same) = 1/2^(n-1) * P(same set of previous vertices are possible next time.)


// idea: each individual vertex is only bad if (A) it is chosen and (B) it is on different side

// imagine we have L vertices before, R vertices after.

// fix positions for each of them: (N choose 1 + L + R)/(N!) = 1/(X!)(N-X)!
// each then remains on the right side: (L!)(R!)/(L + R + 1)!



ll modexp(ll a, ll x) {
    ll r = 1;
    while(x) {
        if(x&1) (r *= a) %= MOD;
        (a *= a) %= MOD;
        x >>= 1;
    }
    return r;
}

ll modinv(ll x) {return modexp(x, MOD-2);}

vector<ll> facts(100001);
vector<ll> ifacts(100001);

ll nck(ll n, ll k) {
    ll r = facts[n];
    r *= ifacts[k]; r %= MOD;
    r *=ifacts[n-k]; r %= MOD;
    return r;
}

const ll MAXN = 101;

int main() {
    facts[0] = 1;
    for(ll i = 1; i < facts.size(); i++) facts[i] = facts[i-1]*i % MOD;
    ifacts.back() = modinv(facts.back());
    for(ll i = facts.size()-2; i >= 0; i--) {
        ifacts[i] = (i+1)*ifacts[i+1] % MOD;
    }

    vector<ll> anses(MAXN);
    vector<ll> bylr(MAXN);
    bylr[0]=1;

    ll one_half = modinv(2);

    anses[1]=1;

    

    for(ll i = 2; i < anses.size(); i++) {
        anses[i] = anses[i-1];
        ll goods = 0;

        goods = ((modexp(2,i)-1+MOD)%MOD)*modinv(i) %MOD;
        goods %= MOD;
        anses[i] *= goods;
        anses[i] %= MOD;

        (anses[i] *= modexp(one_half, 2*(i-1))) %= MOD;
    }

    ll T; cin >> T; while(T--) {
        ll N; cin >> N;

        ll ans = 1-anses[N] + MOD;
        ans %= MOD;
        cout << ans << "\n";
    }
    
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 4436kb

input:

4
1
2
3
100

output:

0
375000004
117187502
778748905

result:

ok 4 number(s): "0 375000004 117187502 778748905"

Test #2:

score: 0
Accepted
time: 0ms
memory: 4572kb

input:

5
1
2
3
4
5

output:

0
375000004
117187502
213897708
995024095

result:

ok 5 number(s): "0 375000004 117187502 213897708 995024095"

Test #3:

score: -100
Runtime Error

input:

100000
64268
66535
9758
42907
84212
83488
27748
86198
80658
11614
93419
2528
96160
79473
83517
43109
37111
46603
93665
54540
84236
62717
24719
57225
8333
15728
40821
31719
13096
75018
76890
46244
75863
59618
67460
10326
84775
11276
83363
72071
9353
94316
9469
3969
78568
53071
96835
50125
2728
46756
...

output:


result: