QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#816846#9870. ItemsHuTaoWA 1161ms35444kbC++142.7kb2024-12-16 18:35:402024-12-16 18:35:41

Judging History

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

  • [2024-12-16 18:35:41]
  • 评测
  • 测评结果:WA
  • 用时:1161ms
  • 内存:35444kb
  • [2024-12-16 18:35:40]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 1 << 20 | 5;
const double PI = acos(-1);

namespace Poly{
    struct Complex{
        double a, b;
        inline Complex operator + (const Complex &x)
        {
            return {a + x.a, b + x.b};
        }
        inline Complex operator - (const Complex &x)
        {
            return {a - x.a, b - x.b};
        }
        inline Complex operator * (const Complex &x)
        {
            return {a * x.a - b * x.b, a * x.b + b * x.a};
        }
    };
    Complex f[N];

    inline void FFT(Complex a[], int n, int ty)
    {
        for(int i = 0, j = 0; i < n; i ++ )
        {
            if(i < j) swap(a[i], a[j]);
            for(int k = n >> 1; (j ^= k) < k; k >>= 1) ;
        }
        static Complex w[N];
        w[0] = {1, 0};
        for(int i = 1; i < n; i <<= 1)
        {
            Complex wi = {cos(PI / i), sin(PI / i) * ty};
            for(int j = i - 2; j >= 0; j -= 2)
            {
                w[j] = w[j >> 1];
                w[j + 1] = w[j] * wi;
            }
            for(int j = 0; j < n; j += i << 1)
                for(int k = j; k < j + i; k ++ )
                {
                    Complex t1 = a[k], t2 = a[k + i] * w[k - j];
                    a[k] = t1 + t2, a[k + i] = t1 - t2;
                }
        }
        if(ty == -1)
        {
            double t = 1.0 / n;
            for(int i = 0; i < n; i ++ ) a[i].a *= t;
        }
    }

    int n, k;
    Complex x[N], y[N];
    inline void Init(int _n)
    {
        n = _n;
        k = 1;
        while(k < 2 * n) k <<= 1;
    }
    inline void Mul(int a[], int b[])
    {
        for(int i = 0; i < k; i ++ ) x[i].a = x[i].b = y[i].a = y[i].b = 0;
        for(int i = 0; i < n; i ++ ) x[i].a = a[i], y[i].a = b[i];
        FFT(x, k, 1), FFT(y, k, 1);
        for(int i = 0; i < k; i ++ ) x[i] = x[i] * y[i];
        FFT(x, k, -1);
        for(int i = 0; i < n; i ++ ) a[i] = int(x[i + n / 2].a + 0.5) != 0;
    }
    inline void ksm(int n, int a[], int b[])
    {
        while(n)
        {
            if(n & 1) Mul(b, a);
            Mul(a, a);
            n >>= 1; 
        }
    }
}

int n, m;
int a[N], b[N];

int main()
{
    int T;
    scanf("%d", &T);
    while(T -- )
    {
        scanf("%d%d", &n, &m);
        int t = m / n, k = n + 2;
        for(int i = 0; i < k * 2; i ++ ) a[i] = b[i] = 0;
        for(int i = 1; i <= n; i ++ )
        {
            int x;
            scanf("%d", &x);
            a[k + x - t] = 1;
        }
        b[k] = 1;
        Poly::Init(k * 2);
        Poly::ksm(n, a, b);
        puts(b[k + m % n] ? "Yes" : "No");
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 14128kb

input:

4
5 25
0 0 0 0 5
5 11
4 4 4 5 5
5 0
1 2 3 4 5
5 25
0 1 2 3 4

output:

Yes
No
No
No

result:

ok 4 token(s): yes count is 1, no count is 3

Test #2:

score: 0
Accepted
time: 7ms
memory: 14156kb

input:

1314
1 0
0
1 0
1
1 1
0
1 1
1
2 0
0 0
2 0
0 1
2 0
0 2
2 0
1 0
2 0
1 1
2 0
1 2
2 0
2 0
2 0
2 1
2 0
2 2
2 1
0 0
2 1
0 1
2 1
0 2
2 1
1 0
2 1
1 1
2 1
1 2
2 1
2 0
2 1
2 1
2 1
2 2
2 2
0 0
2 2
0 1
2 2
0 2
2 2
1 0
2 2
1 1
2 2
1 2
2 2
2 0
2 2
2 1
2 2
2 2
2 3
0 0
2 3
0 1
2 3
0 2
2 3
1 0
2 3
1 1
2 3
1 2
2 3
2 0...

output:

Yes
No
No
Yes
Yes
Yes
Yes
Yes
No
No
Yes
No
No
No
Yes
No
Yes
No
No
No
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
No
No
No
No
Yes
No
Yes
No
No
No
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
No
Yes
No
No
No
Yes
No
No
No
Yes
Yes
Yes...

result:

ok 1314 token(s): yes count is 732, no count is 582

Test #3:

score: 0
Accepted
time: 45ms
memory: 14036kb

input:

10000
4 1
0 0 0 0
4 1
0 0 0 1
4 1
0 0 0 2
4 1
0 0 0 3
4 1
0 0 0 4
4 1
0 0 1 0
4 1
0 0 1 1
4 1
0 0 1 2
4 1
0 0 1 3
4 1
0 0 1 4
4 1
0 0 2 0
4 1
0 0 2 1
4 1
0 0 2 2
4 1
0 0 2 3
4 1
0 0 2 4
4 1
0 0 3 0
4 1
0 0 3 1
4 1
0 0 3 2
4 1
0 0 3 3
4 1
0 0 3 4
4 1
0 0 4 0
4 1
0 0 4 1
4 1
0 0 4 2
4 1
0 0 4 3
4 1
0 ...

output:

No
Yes
No
No
No
Yes
Yes
Yes
Yes
Yes
No
Yes
No
No
No
No
Yes
No
No
No
No
Yes
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
No
No
No
Yes
Yes
Yes
Yes
Yes
No
Yes
No
No
No
No
Yes
No
No
No
No
Yes
No
No
No
No
Yes
No
No
No
Yes
Yes
Yes
Yes
...

result:

ok 10000 token(s): yes count is 6168, no count is 3832

Test #4:

score: 0
Accepted
time: 10ms
memory: 14212kb

input:

1612
5 0
0 0 0 0 0
5 0
1 1 1 1 1
5 0
0 1 1 1 1
5 0
2 2 2 2 2
5 0
0 2 2 2 2
5 0
1 2 2 2 2
5 0
0 1 2 2 2
5 0
3 3 3 3 3
5 0
0 3 3 3 3
5 0
1 3 3 3 3
5 0
0 1 3 3 3
5 0
2 3 3 3 3
5 0
0 2 3 3 3
5 0
1 2 3 3 3
5 0
0 1 2 3 3
5 0
4 4 4 4 4
5 0
0 4 4 4 4
5 0
1 4 4 4 4
5 0
0 1 4 4 4
5 0
2 4 4 4 4
5 0
0 2 4 4 4
5...

output:

Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
No
No
Yes
No
No
No
Yes
No
No
No
Yes
No
No
No
Yes
No
No
No
Yes
No
No
No
Yes
No
No
No...

result:

ok 1612 token(s): yes count is 864, no count is 748

Test #5:

score: 0
Accepted
time: 22ms
memory: 14232kb

input:

4662
6 0
0 0 0 0 0 0
6 0
1 1 1 1 1 1
6 0
0 1 1 1 1 1
6 0
2 2 2 2 2 2
6 0
0 2 2 2 2 2
6 0
1 2 2 2 2 2
6 0
0 1 2 2 2 2
6 0
3 3 3 3 3 3
6 0
0 3 3 3 3 3
6 0
1 3 3 3 3 3
6 0
0 1 3 3 3 3
6 0
2 3 3 3 3 3
6 0
0 2 3 3 3 3
6 0
1 2 3 3 3 3
6 0
0 1 2 3 3 3
6 0
4 4 4 4 4 4
6 0
0 4 4 4 4 4
6 0
1 4 4 4 4 4
6 0
0 1...

output:

Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No...

result:

ok 4662 token(s): yes count is 2730, no count is 1932

Test #6:

score: -100
Wrong Answer
time: 1161ms
memory: 35444kb

input:

1
100000 9999999999
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 9...

output:

Yes

result:

wrong answer expected NO, found YES [1st token]