QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#741291#2529. NeedleNMK#WA 19ms9932kbC++171.7kb2024-11-13 14:02:172024-11-13 14:02:17

Judging History

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

  • [2024-11-13 14:02:17]
  • 评测
  • 测评结果:WA
  • 用时:19ms
  • 内存:9932kb
  • [2024-11-13 14:02:17]
  • 提交

answer

#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
using namespace std;

using ll = long long;
using vi = vector<ll>;
using cd = complex<double>;
const double PI = acos(-1);

void fft(vector<cd> &a, bool inv) {
    int n = a.size();
    for (int i = 1, j = 0, bit; i < n; i++) {
        for (bit = n/2; j & bit; bit /=2 ) j ^= bit;
        j += bit;
        if (i < j) swap(a[i], a[j]);
    }
    for (int len = 2; len <= n; len *= 2) {
        double ang = 2 * PI / len * (inv ? -1 : 1);
        cd wlen(cos(ang), sin(ang));
        for (int i = 0; i < n; i += len) {
            cd w(1);
            for (int j = 0; j < len/2; j++) {
                cd u = a[i+j], v = a[i+j+len/2] * w;
                a[i+j] = u+v, a[i+j+len/2] = u-v;
                w *= wlen;
            }
        }
    }
    if (inv) for (cd &x : a) x /= n;
}

vi conv(vi const &a, vi const &b) {
    vector<cd> fa(all(a)), fb(all(b));
    int n = 1;
    while (n < a.size() + b.size()) n *= 2;
    fa.resize(n), fb.resize(n), fft(fa, 0), fft(fb, 0);
    for (int i = 0; i < n; i++) fa[i] *= fb[i];
    fft(fa, 1);
    
    vi r(n);
    for (int i = 0; i < n; ++i) r[i] = round(fa[i].real());
    return r;
}

const ll N = 5e4+3, X = 6e4+3;
ll n[3];
vi a[3];

int main() {
    cin.tie(0)->sync_with_stdio(0);
    for (int i = 0; i < 3; ++i) {
        cin >> n[i];
        a[i].resize(X);
        for (int j = 0; j < n[i]; ++j) {
            int x; cin >> x;
            a[i][x+30000] = 1;
        }
    }
    auto r = conv(a[0], a[2]);
    ll ans = 0;
    for (int j = 0; 2*j < X; ++j) {
        if (a[1][j]) {
            if (r[2*j]) {
                ans += r[2*j];
            }
        }
    }
    
    cout << ans;
}

詳細信息

Test #1:

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

input:

100
-71 -146 -137 -184 -174 -88 -43 -169 -126 -48 -68 -20 -78 -57 -191 -138 -70 -147 -103 -150 -152 -79 -156 -49 -22 -151 -31 -19 -10 -91 -194 -109 -148 -157 -7 -154 -26 -144 -53 -140 -122 -145 -38 -56 -8 -188 -123 -117 -11 -142 -61 -84 -120 -33 -89 -171 -105 -59 -60 -130 -114 -36 -82 -12 -177 -13 -...

output:

1223

result:

ok single line: '1223'

Test #2:

score: -100
Wrong Answer
time: 19ms
memory: 9932kb

input:

100
-40 -78 -88 -81 -14 -47 -9 28 -62 86 61 71 -95 62 97 80 -8 -44 -52 76 13 14 -93 43 23 -21 -37 -33 -85 -29 16 -39 45 48 77 -49 -67 32 -83 83 36 -28 -87 -86 -76 -5 -46 -80 -4 58 -66 9 10 26 -45 -16 56 -50 40 -65 57 -89 30 92 -79 93 73 8 85 24 46 -75 96 29 -1 -100 79 12 -12 -10 -69 -20 -48 -71 20 -...

output:

241

result:

wrong answer 1st lines differ - expected: '437', found: '241'