QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#179051#5747. Persian CasinotselmegkhWA 24ms5324kbC++202.3kb2023-09-14 17:13:362023-09-14 17:13:38

Judging History

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

  • [2023-09-14 17:13:38]
  • 评测
  • 测评结果:WA
  • 用时:24ms
  • 内存:5324kb
  • [2023-09-14 17:13:36]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
using namespace std;

const int N = 2e5 + 5, inf = 1e9, mod = 1e9 + 9;
#define pb push_back
#define mp make_pair
#define ll long long
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define sz(x) (int)x.size()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

template<int M>
struct Mint {
  int x;
  Mint(): x(0) { }
  Mint(int y) {
    x = y % M;
    if (x < 0) x += M;
  }
  Mint(long long y) {
    x = y % M;
    if (x < 0) x += M;
  }
  int get() const {return x;}
  bool operator==(const Mint &r) const {return x==r.x;}
  Mint &operator+=(const Mint &r) {if((x+=r.x)>=M) x-=M; return *this;}
  Mint &operator-=(const Mint &r) {if((x+=M-r.x)>=M) x-=M; return *this;}
  Mint &operator*=(const Mint &r) {x=(long long)x*r.x%M; return *this;}
  Mint &operator/=(const Mint &r) {x=(long long)x*r.inv().x%M; return *this;}
  Mint operator+(const Mint &r) const {return Mint(*this)+=r;}
  Mint operator-(const Mint &r) const {return Mint(*this)-=r;}
  Mint operator*(const Mint &r) const {return Mint(*this)*=r;}
  Mint operator/(const Mint &r) const {return Mint(*this)/=r;}
  Mint inv() const {
    int a = x, b = M, u = 1, v = 0;
    while(b) {
      int t = a / b;
      a -= t * b; std::swap(a, b);
      u -= t * v; std::swap(u, v);
    }
    if(u < 0) u += M;
    Mint res; res.x = (unsigned)u;
    return res;
  }
};

typedef Mint<mod> mint;
mint fac[N], inv[N];

mint ncr(int n, int k){
    if(k > n)return mint(0ll);
    if(k == 0)return mint(1ll);
    return fac[n] * inv[k] * inv[n - k];
}
void solve(){
    int n, m;
    cin >> n >> m;

    if(pow(2, m) < n - m){
        cout << "bankrupt\n";
        return;
    }
    mint ans(0ll);
    for(int i = 0; i <= m; i++){
        ans += ncr(n, i);
    }
    cout << ans.x << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t = 1;
    cin >> t;

    fac[0] = mint(1);
    for(int i = 1; i < N; i++){
        fac[i] = fac[i - 1] * mint(i);
        inv[i] = fac[i].inv();
    }
    while(t--){
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 15ms
memory: 5324kb

input:

4
2 1
4 1
3 2
57639 34614

output:

3
bankrupt
7
869788168

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 24ms
memory: 5240kb

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
857164589
919274229
886008600
422741550
229676734
66137152
898506279
95608855
78287335
89291935
599857760
378517272
779874547
58872199
492901833
640116450
bankrupt
73638239...

result:

wrong answer 14th lines differ - expected: '857164590', found: '857164589'