QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#234358#5039. Black and WhiteCSU2023#WA 10ms11540kbC++141.8kb2023-11-01 16:32:032023-11-01 16:32:04

Judging History

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

  • [2023-11-01 16:32:04]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:11540kb
  • [2023-11-01 16:32:03]
  • 提交

answer

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::ios;
const int mod = 998244353;
const int N = 1e6 + 5;
int n, m, k, lim = 1e6, T_data, fac[N], ifac[N];

inline int quick_pow(int x, int k)
{
    int res = 1;
    while (k)
    {
        if (k & 1)
            res = 1ll * res * x % mod;
        x = 1ll * x * x % mod;
        k >>= 1;
    }
    return res;
}

inline int C(int n, int m)
{
    if (n < 0 || m < 0 || n < m)
        return 0;
    return 1ll * fac[n] * ifac[n - m] % mod * ifac[m] % mod;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    fac[0] = 1;
    for (int i = 1; i <= lim; ++i)
        fac[i] = 1ll * i * fac[i - 1] % mod;
    ifac[lim] = quick_pow(fac[lim], mod - 2);
    for (int i = lim; i >= 1; --i)
        ifac[i - 1] = 1ll * ifac[i] * i % mod;

    cin >> T_data;
    while (T_data--)
    {
        cin >> n >> m >> k;
        std::swap(n, m);
        int x = 0, y = 0, c = 0;
        while (x < n)
        {
            if ((x & 1) == (y & 1))
                --c;
            else 
                ++c;
            ++x;
        }
        while (y < m)
        {
            if ((x & 1) == (y & 1))
                ++c;
            else 
                --c;
            ++y;
        }
        int ans = 4 * k + c;
        x = (n + m + 1) >> 1, y = (n + m) - x;
        if ((ans + x - y) % 2 != 0)
            cout << "0\n";
        else 
        {
            int tot = 0, tmp = (ans + x - y) / 2;
            for (int a1 = 0; a1 <= x; ++a1)
            {
                int a2 = a1 - tmp;
                if (a1 + a2 == m)
                    tot = (1ll * C(x, a1) * C(y, a2) + tot) % mod;
            }
            cout << tot << '\n';
        }
    }
}

详细

Test #1:

score: 100
Accepted
time: 10ms
memory: 11500kb

input:

5
1 1 0
1 1 -1
2 2 1
2 2 0
4 4 1

output:

1
0
1
4
16

result:

ok 5 number(s): "1 0 1 4 16"

Test #2:

score: -100
Wrong Answer
time: 10ms
memory: 11540kb

input:

100
1 1 -10
1 1 -9
1 1 -8
1 1 -7
1 1 -6
1 1 -5
1 1 -4
1 1 -3
1 1 -2
1 1 -1
1 1 0
1 1 1
1 1 2
1 1 3
1 1 4
1 1 5
1 1 6
1 1 7
1 1 8
1 1 9
1 1 10
1 2 -10
1 2 -9
1 2 -8
1 2 -7
1 2 -6
1 2 -5
1 2 -4
1 2 -3
1 2 -2
1 2 -1
1 2 0
1 2 1
1 2 2
1 2 3
1 2 4
1 2 5
1 2 6
1 2 7
1 2 8
1 2 9
1 2 10
1 3 -10
1 3 -9
1 3 -...

output:

0
0
0
0
0
0
0
0
0
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
3
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
3
0
0
0
0

result:

wrong answer 31st numbers differ - expected: '0', found: '1'