Submission #420315


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define repu(i, a, b) for (int i = (a); i < (b); ++i)
#define repd(i, a, b) for (int i = (a); i > (b); --i)
#define mem(a, x) memset(a, x, sizeof(a))
#define all(a) a.begin(), a.end()
#define uni(a) a.erase(unique(all(a)), a.end())
#define count_bits(x) __builtin_popcount(x)
#define count_bitsll(x) __builtin_popcountll(x)
#define least_bits(x) __builtin_ffs(x)
#define least_bitsll(x) __builtin_ffsll(x)
#define most_bits(x) 32 - __builtin_clz(x)
#define most_bitsll(x) 64 - __builtin_clz(x)

vector<string> split(const string &s, char c) {
	vector<string> v;
	stringstream ss(s);
	string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}

#define error(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }

void err(vector<string>::iterator it) {}

template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T> inline T tmin(T a, T b) {return (a < b) ? a : b;}
template<class T> inline T tmax(T a, T b) {return (a > b) ? a : b;}
template<class T> inline void amax(T &a, T b) {if (b > a) a = b;}
template<class T> inline void amin(T &a, T b) {if (b < a) a = b;}
template<class T> inline T tabs(T a) {return (a > 0) ? a : -a;}
template<class T> T gcd(T a, T b) {while (b != 0) {T c = a; a = b; b = c % b;} return a;}


typedef complex<double> C;
int fft_n;
vector<C> omega;

ll mod_pow(ll x, ll y = MOD - 2) {
    ll res = 1;
    while (y > 0) {
        if (y & 1) res = (res * x) % MOD;
        x = (x * x) % MOD;
        y >>= 1;
    }
    return res;
}

void init_fft(int n) {
	fft_n = n;
	omega.resize(n);
	double angle = 2 * M_PI / n;
	repu(i, 0, n) {
		omega[i] = C(cos(i * angle), sin(i * angle));
	}
}

void fft(vector<C> & a) {
	int n = a.size();
	if (n == 1) return;
	int half = n >> 1;
	vector<C> even(half), odd(half);
	for (int i = 0, j = 0; i < n; i += 2, ++j) {
		even[j] = a[i];
		odd[j] = a[i+1];
	}
	fft(even); fft(odd);
	for (int i = 0, fact = fft_n / n; i < half; ++i) {
		C twiddle = odd[i] * omega[i * fact];
		a[i] = even[i] + twiddle;
		a[i + half] = even[i] - twiddle;
	}
}


void mul_fft(const vector<ll> &a, const vector<ll> &b, vector<ll> &res) {
	vector<C> fa(a.begin(), a.end()), fb(b.begin(), b.end());
	int n = 1;
	while (n < 2 * max (a.size(), b.size())) n <<= 1;
	fa.resize(n); fb.resize(n);
	
	init_fft(n);
	fft(fa); fft(fb);
	repu(i, 0, n) fa[i] = conj(fa[i] * fb[i]);
	fft(fa);
	res.resize (n);
	repu(i, 0, n) {
		res[i] = (ll) (fa[i].real() / n + 0.5);
	}
}


int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);
	
	int n;
	
	cin >> n;
	vector<ll> A(n), B(n);
	repu(i, 0, n) cin >> A[i] >> B[i];
	
	vector<ll> ret;
	mul_fft(A, B, ret);
	printf("0\n");
	repu(i, 0, n + n - 1) printf("%lld\n", ret[i]);
	
	
	return 0;
}

Submission Info

Submission Time
Task C - 高速フーリエ変換
User rantd
Language C++ (GCC 4.9.2)
Score 100
Code Size 3078 Byte
Status AC
Exec Time 538 ms
Memory 22888 KB

Compile Error

./Main.cpp:28:30: warning: variadic templates only available with -std=c++11 or -std=gnu++11
 template<typename T, typename... Args>
                              ^
./Main.cpp:29:52: warning: variadic templates only available with -std=c++11 or -std=gnu++11
 void err(vector<string>::iterator it, T a, Args... args) {
                                                    ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 1
AC × 33
Set Name Test Cases
Sample 00_sample_01
All 00_sample_01, 01_00_01, 01_01_19, 01_02_31, 01_03_22, 01_04_31, 01_05_40, 01_06_15, 01_07_39, 01_08_28, 01_09_30, 01_10_23, 01_11_33, 01_12_11, 01_13_28, 01_14_41, 01_15_26, 01_16_49, 01_17_34, 01_18_02, 01_19_33, 01_20_29, 02_00_51254, 02_01_82431, 02_02_17056, 02_03_34866, 02_04_6779, 02_05_65534, 02_06_65535, 02_07_65536, 02_08_65537, 02_09_65538, 02_10_100000
Case Name Status Exec Time Memory
00_sample_01 AC 25 ms 816 KB
01_00_01 AC 25 ms 804 KB
01_01_19 AC 26 ms 800 KB
01_02_31 AC 27 ms 924 KB
01_03_22 AC 26 ms 804 KB
01_04_31 AC 26 ms 804 KB
01_05_40 AC 27 ms 800 KB
01_06_15 AC 26 ms 796 KB
01_07_39 AC 27 ms 804 KB
01_08_28 AC 26 ms 808 KB
01_09_30 AC 27 ms 924 KB
01_10_23 AC 27 ms 800 KB
01_11_33 AC 27 ms 808 KB
01_12_11 AC 26 ms 920 KB
01_13_28 AC 27 ms 800 KB
01_14_41 AC 25 ms 932 KB
01_15_26 AC 27 ms 924 KB
01_16_49 AC 23 ms 920 KB
01_17_34 AC 25 ms 924 KB
01_18_02 AC 26 ms 796 KB
01_19_33 AC 29 ms 804 KB
01_20_29 AC 26 ms 792 KB
02_00_51254 AC 277 ms 11860 KB
02_01_82431 AC 537 ms 22616 KB
02_02_17056 AC 130 ms 6148 KB
02_03_34866 AC 254 ms 11548 KB
02_04_6779 AC 50 ms 2180 KB
02_05_65534 AC 302 ms 12016 KB
02_06_65535 AC 295 ms 12064 KB
02_07_65536 AC 301 ms 12060 KB
02_08_65537 AC 509 ms 22300 KB
02_09_65538 AC 504 ms 22300 KB
02_10_100000 AC 538 ms 22888 KB