QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#772929#1792. Beer BillI_be_wannaWA 0ms3676kbC++171.5kb2024-11-22 23:01:292024-11-22 23:01:29

Judging History

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

  • [2024-11-22 23:01:29]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3676kb
  • [2024-11-22 23:01:29]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define IO std::ios::sync_with_stdio(false)
#define int long long
#define INF 0x3f3f3f3f

const int maxn = 1010;
int fact[maxn];
inline int extgcd(int a,int b,int &x,int &y) {
    int d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}
inline int mod_inverse(int a,int m){
    int x,y;
    extgcd(a,m,x,y);
    return (m + x % m) % m;
}
inline int mod_fact(int n,int p,int &e) {
    e = 0;
    if (n == 0) return 1;
    int res = mod_fact(n / p, p, e);
    e += n / p;

    if (n / p % 2 != 0) return res * (p - fact[n % p] % p);
    return res * fact[n % p] % p;
}
inline int mod_comb(int n,int k,int p) {
    if (n < 0 || k < 0 || n < k) return 0;
    int e1, e2, e3;
    int a1 = mod_fact(n, p, e1), a2 = mod_fact(k, p, e2), a3 = mod_fact(n - k, p, e3);
    if (e1 > e2 + e3) return 0;
    return a1 * mod_inverse(a2 * a3 % p, p) % p;
}
int A,B,K,C;
const int mod = 1e9 + 7;
signed main() {
    IO;
    cin >> A >> B >> K >> C;
    fact[0] = 0, fact[1] = 1;
    for (int i = 2; i <= maxn; i++) fact[i] = fact[i - 1] * i % mod;
    if (A != C && B != C) {
        cout << 0 << endl;
    } else {
        if (A == B) cout << K << endl;
        else {
            int ans = 0;
            for (int i = 1; i <= K; i++) {
                ans = (ans + i * mod_comb(K, i, mod) + mod) % mod;
            }
            cout << ans << endl;
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
893,-|||||||||
|||
|||||||||||||||||||||||||||||||||||||||||||||||||||
||||||||||||||||||||
545,-|||||||||||||||||||||||
810,-|
699,-|||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||...

output:

0

result:

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