QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#353295#8325. 重塑时光BalintR15 678ms136820kbC++203.6kb2024-03-14 01:38:242024-03-14 01:38:25

Judging History

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

  • [2024-03-14 01:38:25]
  • 评测
  • 测评结果:15
  • 用时:678ms
  • 内存:136820kb
  • [2024-03-14 01:38:24]
  • 提交

answer

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

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef complex<double> cpx;
template <typename T> using minPq = priority_queue<T, vector<T>, greater<T>>;
#define ms(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define fs first
#define sn second
#define ALL(v) begin(v), end(v)
#define SZ(v) ((int) (v).size())
#define lbv(v, x) (lower_bound(ALL(v), x) - (v).begin())
#define ubv(v, x) (upper_bound(ALL(v), x) - (v).begin())
template <typename T> inline void UNIQUE(vector<T> &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
#define FR(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define dbg(x) {cerr << #x << ' ' << x << endl;}
#define dbgArr(arr, n) {cerr << #arr; FR(_i, n) cerr << ' ' << (arr)[_i]; cerr << endl;}
template <typename T, typename U>
ostream& operator<<(ostream &os, pair<T, U> p){return os << "(" << p.fs << ", " << p.sn << ")";}

const int MOD = 1e9 + 7;
const int MX = 100;

namespace Mod {
    int fact[MX], ifact[MX];

    ll fpow(ll a, ll b){
        ll res = 1;
        for(a %= MOD; b; b >>= 1){
            if(b & 1) res = res * a % MOD;
            a = a * a % MOD;
        }
        return res;
    }

    inline ll modInv(ll a){
        return fpow(a, MOD-2);
    }

    inline ll choose(ll a, ll b){
        return (ll) fact[a] * ifact[b] % MOD * ifact[a-b] % MOD;
    }

    void initFact(){
        fact[0] = 1;
        for(int i = 1; i < MX; i++) fact[i] = (ll) fact[i-1]*i % MOD;
        ifact[MX-1] = modInv(fact[MX-1]);
        for(int i = MX-1; i > 0; i--) ifact[i-1] = (ll) ifact[i]*i % MOD;
    }
}
using namespace Mod;

const int MN = 15;
const int MP = 1 << MN;
int n, m, k, mask;
int adjMat[MN];
bitset<MP> isGood[MP];
int dp[MN+1][MP];

void genIsGood(){
    FR(s, 1<<n){
        int rem = mask ^ s;
        FR(i, n) if((s >> i) & 1) rem &= ~adjMat[i];
        for(int s2 = rem; s2; s2 = (s2-1) & rem) isGood[s][s2] = true;
        isGood[s][0] = true;
    }
}

void genDp0(){
    dp[0][0] = 1;
    FOR(s, 1, 1<<n){
        ll v = 0;
        FR(i, n) if((s >> i) & 1){
            int rem = s ^ (1 << i);
            if(!(adjMat[i] & rem)) v += dp[0][rem];
        }
        dp[0][s] = v % MOD;
    }
}

void genDp(int cuts){
    FOR(s, 1, 1<<n){
        //int pop = __builtin_popcount(s);
        //if(pop <= cuts) continue;

        ll v = 0;
        for(int s1 = (s-1) & s; s1; s1 = (s1-1) & s){
            int s2 = s ^ s1;
            //if(cuts == 2 && s == 7) cerr << s1 << ' ' << s2 << endl;
            v += dp[0][s1] * dp[cuts-1][s2] * (isGood[s1][s2] || isGood[s2][s1]);
        }
        dp[cuts][s] = v;
    }
}

int main(){
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> n >> m >> k;
    FR(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        adjMat[b] |= 1 << a;
    }
    mask = (1 << n) - 1;

    genIsGood();
    genDp0();
    FOR(i, 1, min(n, k+1)) genDp(i);

    //FR(s, 1<<n) dbgArr(isGood[s], 1<<n);
    //FR(i, min(n, k+1)) dbgArr(dp[i], 1<<n);

    initFact();
    ll num = 0;
    FR(c, min(n, k+1)){
        num += choose(k+1, c+1) * dp[c][mask] % MOD;
    }
    num %= MOD;

    ll denom = (ll) fact[n+k] * ifact[k] % MOD;
    dbg(num);
    dbg(denom);
    cout << num * modInv(denom) % MOD << '\n';
}

详细

Test #1:

score: 5
Accepted
time: 1ms
memory: 5712kb

input:

3 2 0
1 2
1 3

output:

333333336

result:

ok single line: '333333336'

Test #2:

score: 0
Wrong Answer
time: 1ms
memory: 5716kb

input:

5 7 5
1 4
2 3
1 2
4 5
2 5
2 4
1 5

output:

340013230

result:

wrong answer 1st lines differ - expected: '895039689', found: '340013230'

Test #3:

score: 0
Wrong Answer
time: 51ms
memory: 38556kb

input:

13 12 13
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13

output:

-633818209

result:

wrong answer 1st lines differ - expected: '76923078', found: '-633818209'

Test #4:

score: 0
Wrong Answer
time: 169ms
memory: 71040kb

input:

14 13 14
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14

output:

76805085

result:

wrong answer 1st lines differ - expected: '535714290', found: '76805085'

Test #5:

score: 5
Accepted
time: 3ms
memory: 71304kb

input:

14 13 0
2 9
1 2
1 3
3 8
6 11
2 7
1 5
5 12
2 13
3 14
3 10
3 6
2 4

output:

700595243

result:

ok single line: '700595243'

Test #6:

score: 0
Wrong Answer
time: 245ms
memory: 72108kb

input:

14 13 14
9 11
2 9
5 10
4 6
10 13
2 3
2 7
4 12
2 4
3 8
7 14
3 5
1 2

output:

-991426716

result:

wrong answer 1st lines differ - expected: '465070080', found: '-991426716'

Test #7:

score: 0
Wrong Answer
time: 41ms
memory: 38552kb

input:

13 0 13

output:

225667504

result:

wrong answer 1st lines differ - expected: '1', found: '225667504'

Test #8:

score: 0
Wrong Answer
time: 204ms
memory: 72092kb

input:

14 91 14
3 4
2 10
3 10
1 13
6 8
5 6
10 13
7 8
4 9
4 7
3 7
13 14
2 12
1 3
6 9
9 14
1 10
2 9
7 11
9 11
3 12
8 10
4 13
5 9
11 12
5 14
8 12
8 13
5 13
1 5
6 11
9 13
2 5
1 14
7 14
4 14
3 5
5 11
6 12
1 2
7 10
1 4
1 8
6 10
3 8
6 13
10 14
7 12
10 11
2 13
8 11
11 13
6 7
10 12
3 14
4 5
1 6
2 14
5 10
8 14
4 8
1...

output:

92740002

result:

wrong answer 1st lines differ - expected: '4362623', found: '92740002'

Test #9:

score: 0
Wrong Answer
time: 0ms
memory: 7788kb

input:

9 15 9
1 2
3 5
2 8
4 8
1 4
2 5
2 7
4 5
1 9
6 8
6 9
1 3
3 7
5 9
5 8

output:

677826935

result:

wrong answer 1st lines differ - expected: '426526937', found: '677826935'

Test #10:

score: 0
Wrong Answer
time: 0ms
memory: 7760kb

input:

9 14 9
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
4 5
6 8
4 7
6 7
3 8
4 6

output:

820700324

result:

wrong answer 1st lines differ - expected: '214820829', found: '820700324'

Test #11:

score: 5
Accepted
time: 3ms
memory: 38424kb

input:

13 68 0
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 12
2 13
3 4
3 5
3 6
3 7
3 8
3 9
3 10
3 11
3 12
3 13
4 5
4 6
4 7
4 8
4 9
4 10
4 11
4 12
4 13
5 6
5 7
5 8
5 9
5 10
5 11
5 12
5 13
6 7
6 8
6 9
6 10
6 11
6 12
6 13
7 8
7 10
7 11
7 12
7 13
8 13
9 10
9 11
9 12
9 13...

output:

65784302

result:

ok single line: '65784302'

Test #12:

score: 0
Wrong Answer
time: 64ms
memory: 38888kb

input:

13 39 13
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
3 4
3 5
3 6
3 7
3 8
3 9
3 10
3 11
3 12
3 13
4 8
4 9
4 10
4 12
4 13
5 6
5 7
5 10
5 11
5 13
6 7
6 11
6 13
8 9
8 12
8 13
11 13

output:

947158482

result:

wrong answer 1st lines differ - expected: '361557272', found: '947158482'

Test #13:

score: 0
Wrong Answer
time: 192ms
memory: 71832kb

input:

14 11 14
2 13
4 11
4 14
5 14
6 9
6 14
7 11
9 14
10 12
10 14
12 14

output:

-186853395

result:

wrong answer 1st lines differ - expected: '696132576', found: '-186853395'

Test #14:

score: 0
Wrong Answer
time: 210ms
memory: 71708kb

input:

14 46 14
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
2 9
2 10
2 11
2 13
2 14
3 4
3 6
3 10
3 11
3 12
3 13
3 14
4 6
4 10
4 11
4 12
4 13
4 14
5 7
5 8
5 9
5 11
5 13
5 14
7 8
7 9
7 14
10 11
10 13
10 14
11 13
11 14
13 14

output:

927072072

result:

wrong answer 1st lines differ - expected: '258614192', found: '927072072'

Test #15:

score: 0
Wrong Answer
time: 210ms
memory: 71628kb

input:

14 70 14
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
2 3
2 4
2 5
2 7
2 8
2 9
2 10
2 11
2 12
2 13
2 14
3 11
3 13
3 14
4 5
4 7
4 8
4 10
4 11
4 12
4 13
4 14
5 7
5 8
5 10
5 12
5 13
5 14
6 7
6 8
6 9
6 10
6 11
6 12
6 13
6 14
7 8
7 10
7 12
7 13
7 14
8 10
8 12
8 13
8 14
9 11
9 12
9 13
9 14
10 1...

output:

754790552

result:

wrong answer 1st lines differ - expected: '209616080', found: '754790552'

Test #16:

score: 0
Wrong Answer
time: 210ms
memory: 71724kb

input:

14 69 14
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
2 3
2 5
2 6
2 7
2 9
2 10
2 11
2 12
2 13
2 14
3 5
3 6
3 7
3 9
3 10
3 11
3 12
3 13
3 14
4 7
4 8
4 9
4 10
4 11
4 12
4 13
4 14
5 6
5 7
5 9
5 10
5 11
5 12
5 13
5 14
6 7
6 9
6 10
6 11
6 12
6 13
6 14
7 9
7 10
7 11
7 12
7 13
7 14
8 12
8 13
8 14
9 10
...

output:

948479490

result:

wrong answer 1st lines differ - expected: '701202127', found: '948479490'

Test #17:

score: 0
Wrong Answer
time: 185ms
memory: 72236kb

input:

14 15 14
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
4 6
5 9

output:

905050673

result:

wrong answer 1st lines differ - expected: '263013541', found: '905050673'

Test #18:

score: 0
Wrong Answer
time: 641ms
memory: 136732kb

input:

15 17 15
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
3 13
3 15
13 15

output:

-172849937

result:

wrong answer 1st lines differ - expected: '963180835', found: '-172849937'

Test #19:

score: 0
Wrong Answer
time: 656ms
memory: 136820kb

input:

15 17 15
1 2
1 3
1 4
1 5
1 6
1 7
1 12
1 15
7 12
7 15
8 15
9 15
10 15
11 15
12 15
13 15
14 15

output:

-886889730

result:

wrong answer 1st lines differ - expected: '722208430', found: '-886889730'

Test #20:

score: 0
Wrong Answer
time: 678ms
memory: 136700kb

input:

15 16 15
1 2
1 3
1 10
2 10
3 10
4 5
4 6
4 7
4 8
4 9
4 10
4 11
4 12
4 13
4 14
4 15

output:

-508334954

result:

wrong answer 1st lines differ - expected: '560801339', found: '-508334954'