Submission #420407


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;

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<int> &a, const vector<int> &b, vector<int> &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] = (int) (fa[i].real() / n + 0.5);
	}
}


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

Submission Info

Submission Time
Task C - 高速フーリエ変換
User rantd
Language C++ (GCC 4.9.2)
Score 100
Code Size 2890 Byte
Status AC
Exec Time 521 ms
Memory 21996 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 928 KB
01_00_01 AC 24 ms 928 KB
01_01_19 AC 24 ms 800 KB
01_02_31 AC 23 ms 928 KB
01_03_22 AC 30 ms 796 KB
01_04_31 AC 26 ms 928 KB
01_05_40 AC 25 ms 920 KB
01_06_15 AC 24 ms 924 KB
01_07_39 AC 25 ms 736 KB
01_08_28 AC 22 ms 800 KB
01_09_30 AC 24 ms 804 KB
01_10_23 AC 24 ms 800 KB
01_11_33 AC 25 ms 924 KB
01_12_11 AC 23 ms 792 KB
01_13_28 AC 25 ms 800 KB
01_14_41 AC 24 ms 928 KB
01_15_26 AC 26 ms 776 KB
01_16_49 AC 24 ms 928 KB
01_17_34 AC 22 ms 804 KB
01_18_02 AC 23 ms 928 KB
01_19_33 AC 24 ms 924 KB
01_20_29 AC 24 ms 928 KB
02_00_51254 AC 265 ms 11484 KB
02_01_82431 AC 494 ms 21900 KB
02_02_17056 AC 129 ms 6088 KB
02_03_34866 AC 237 ms 11360 KB
02_04_6779 AC 50 ms 2124 KB
02_05_65534 AC 294 ms 11552 KB
02_06_65535 AC 294 ms 11552 KB
02_07_65536 AC 289 ms 11552 KB
02_08_65537 AC 484 ms 21788 KB
02_09_65538 AC 480 ms 21792 KB
02_10_100000 AC 521 ms 21996 KB