結果

問題 No.723 2つの数の和
ユーザー tonyu0tonyu0
提出日時 2020-07-24 19:01:13
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 292 ms / 2,000 ms
コード長 1,633 bytes
コンパイル時間 1,180 ms
コンパイル使用メモリ 112,564 KB
実行使用メモリ 28,232 KB
最終ジャッジ日時 2023-09-07 23:50:49
合計ジャッジ時間 9,460 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 280 ms
28,120 KB
testcase_01 AC 274 ms
27,900 KB
testcase_02 AC 273 ms
27,836 KB
testcase_03 AC 280 ms
27,896 KB
testcase_04 AC 283 ms
28,092 KB
testcase_05 AC 285 ms
27,948 KB
testcase_06 AC 286 ms
27,960 KB
testcase_07 AC 275 ms
28,008 KB
testcase_08 AC 275 ms
27,988 KB
testcase_09 AC 283 ms
27,896 KB
testcase_10 AC 276 ms
28,088 KB
testcase_11 AC 273 ms
28,020 KB
testcase_12 AC 279 ms
27,892 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 280 ms
28,232 KB
testcase_19 AC 292 ms
27,828 KB
testcase_20 AC 277 ms
27,992 KB
testcase_21 AC 274 ms
27,900 KB
testcase_22 AC 272 ms
27,896 KB
testcase_23 AC 280 ms
27,936 KB
testcase_24 AC 275 ms
27,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <cmath>
#include <complex>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = j; i < (int)n; ++i)

constexpr ll INF = 1LL << 60;
constexpr double PI = 3.1415926535897932384626;
using namespace std;

using C = complex<double>;
vector<C> dft(vector<C>& f, int n, int sgn = 1) {
    if (n == 1) return f;

    vector<C> f0(n / 2), f1(n / 2);
    for (int i = 0; i < n / 2; ++i) {
        f0[i] = f[i * 2 + 0];
        f1[i] = f[i * 2 + 1];
    }
    f0 = dft(f0, n / 2, sgn);
    f1 = dft(f1, n / 2, sgn);

    C zeta(cos(PI * 2 / n), sin(PI * 2 / n) * sgn);
    C pow_zeta = 1;

    for (int i = 0; i < n; ++i) {
        f[i] = f0[i % (n / 2)] + pow_zeta * f1[i % (n / 2)];
        pow_zeta *= zeta;
    }

    return f;
}

vector<C> multiply(vector<C>& g, vector<C>& h) {
    int n_ = (int)g.size() + (int)h.size() + 1;
    int n = 1; while (n < n_) n *= 2;
    g.resize(n); h.resize(n);

    g = dft(g, n);
    h = dft(h, n);

    vector<C> f(n);
    for (int i = 0; i < n; ++i) f[i] = g[i] * h[i];

    // inverse
    f = dft(f, n, -1);
    for (int i = 0; i < n; ++i) f[i] /= n;
    return f;
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);

    ll n, x, t; cin >> n >> x;
    if (x > 200000) {
        cout << 0 << endl;
        return 0;
    }
    vector<C> a(100001), b(100001);
    rep(i, 1, n + 1) {
        cin >> t;
        a[t] += 1;
        b[t] += 1;
    }
    vector<C> c = multiply(a, b);

    cout << (ll)(c[x].real() + 0.5) << endl;
	return 0;
}
0