QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#668231#5747. Persian CasinopropaneTL 132ms5956kbC++201.8kb2024-10-23 12:52:062024-10-23 12:52:11

Judging History

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

  • [2024-10-23 12:52:11]
  • 评测
  • 测评结果:TL
  • 用时:132ms
  • 内存:5956kb
  • [2024-10-23 12:52:06]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
using LL = long long;
const int mod = 1e9 + 9;

void add(int &a, int b){
    a += b;
    if (a >= mod) a -= mod;
}

void sub(int &a, int b){
    a -= b;
    if (a < 0) a += mod;
}

int mul(int a, int b){
    return 1LL * a * b % mod;
}

int qpow(int a, int b){
    int ans = 1;
    while(b){
        if (b & 1) ans = mul(ans, a);
        b >>= 1;
        a = mul(a, a);
    }
    return ans;
}

const int maxn = 2e5 + 5;
int fact[maxn], invfact[maxn], pow2[maxn];

void init(){
    pow2[0] = 1;
    for(int i = 1; i < maxn; i++) pow2[i] = pow2[i - 1] * 2 % mod;
    fact[0] = invfact[0] = 1;
    for(int i = 1; i < maxn; i++){
        fact[i] = mul(fact[i - 1], i);
    }
    invfact[maxn - 1] = qpow(fact[maxn - 1], mod - 2);
    for(int i = maxn - 2; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

int C(int a, int b){
    if (a < 0 or b < 0 or a < b) return 0;
    return mul(fact[a], mul(invfact[b], invfact[a - b]));
}

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    init();
    int T;
    cin >> T;
    while(T--){
        int n, m;
        cin >> n >> m;
        if (m < 30 and (1 << m) < n - m){
            cout << "bankrupt" << '\n';
            continue;
        }
        int p = 1, ans = 0;
        for(int i = 0; i + m <= n; i++){
            int t = C(i + m - 1, m - 1);
            int q = mul(t, qpow(pow2[i + m], mod - 2));
            add(ans, mul(q, pow2[i + m]));
            sub(p, q);
        }
        add(ans, mul(p, pow2[n]));
        cout << ans << '\n';
    }

}

詳細信息

Test #1:

score: 100
Accepted
time: 7ms
memory: 5956kb

input:

4
2 1
4 1
3 2
57639 34614

output:

3
bankrupt
7
869788168

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 132ms
memory: 5916kb

input:

16460
131 83
137 14
140 28
174 145
87 27
56 11
144 67
88 47
154 59
152 138
100 65
71 43
172 142
113 113
87 68
101 52
179 71
60 51
26 18
97 19
147 111
119 57
124 30
130 37
129 77
177 152
179 84
82 21
162 55
152 2
168 23
139 34
131 101
111 89
179 69
144 30
84 50
150 101
32 24
104 41
137 37
82 59
138 1...

output:

861401790
827411823
937669544
814872401
564368688
774329757
382020028
327399098
136919945
13075099
706031307
579851898
54033422
857164590
919274229
886008600
422741550
229676734
66137152
898506279
95608855
78287335
89291935
599857760
378517272
779874547
58872199
492901833
640116450
bankrupt
73638239...

result:

ok 16460 lines

Test #3:

score: -100
Time Limit Exceeded

input:

100000
40029 5
1295 16
50862 5
67072 8
51451 4
57967 7
40886 20
13278 1
61885 12
24790 1
80316 2
8554 8
49717 6
82652 8
83139 5
87135 16
7419 8
91357 12
28565 12
80411 1
83723 1
17818 2
36799 20
86016 7
56546 3
92119 10
46290 1
14836 14
63748 1
72859 1
1668 12
99713 23
65337 24
77683 11
36461 2
7810...

output:


result: