AtCoder Typical Contest 001

Submission #7142996

Source codeソースコード

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <complex>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const double pi = acos(-1);
vector<complex<double>> tmp;
size_t sz = 1;

//mulが勝手に呼び出してくれる
vector<complex<double>> fft(vector<complex<double>> a, bool inv = false){
	size_t mask = sz - 1;
	size_t p = 0;
	for(size_t i = sz >> 1; i >= 1; i >>= 1){
		auto& cur = (p & 1) ? tmp : a;
		auto& nex = (p & 1) ? a : tmp;
		complex<double> e = polar(1., 2 * pi * i * (inv ? -1 : 1) / sz);
		complex<double> w = 1;
		for(size_t j = 0; j< sz; j += i){
			for(size_t k = 0; k < i; k++){
				nex[j + k] = cur[((j << 1) & mask) + k] + w * cur[(((j << 1) + i) & mask) + k];
			}
			w *= e;
		}
		p++;
	}
	if(p & 1) swap(a, tmp);
	if(inv) for(size_t i = 0; i < sz; i++) a[i] /= sz;
	return a;
}

//これを使う. a[i] = 多項式Aにおけるx^iの項の係数, b[i]も同様.
vector<ll> mul(vector<ll> a, vector<ll> b){
	size_t m = a.size() + b.size() - 1;
	sz = 1;
	while(m > sz) sz <<= 1;
	tmp.resize(sz);
	vector<complex<double>> A(sz), B(sz);
	rep(i, a.size()) A[i].real(a[i]);
	rep(i, b.size()) B[i].real(b[i]);
	A = fft(A);
	B = fft(B);
	rep(i, sz) A[i] *= B[i];
	A = fft(A, true);
	a.resize(m);
	rep(i, m) a[i] = round(A[i].real());
	return a;
}

int main(void){
	ll n; cin>>n;
	vector<ll> A,B,C;
	A.push_back(0); B.push_back(0);
	rep(i,n){
		ll a,b;cin>>a>>b;
		A.push_back(a);
		B.push_back(b);
	}
	//多項式Cの係数配列 = 多項式Aの係数配列*多項式Bの係数配列
	C = mul(A,B);
	reps(i,2*n){
		cout<<C[i]<<endl;
	}
	return 0;
}

Submission

Task問題 C - 高速フーリエ変換
User nameユーザ名 Jirotech
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 100
Source lengthソースコード長 2291 Byte
File nameファイル名
Exec time実行時間 434 ms
Memory usageメモリ使用量 19948 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - 00_sample_01
All 100 / 100 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00_sample_01 AC 1 ms 256 KB
01_00_01 AC 1 ms 256 KB
01_01_19 AC 1 ms 256 KB
01_02_31 AC 1 ms 256 KB
01_03_22 AC 1 ms 256 KB
01_04_31 AC 1 ms 256 KB
01_05_40 AC 1 ms 256 KB
01_06_15 AC 1 ms 256 KB
01_07_39 AC 1 ms 256 KB
01_08_28 AC 1 ms 256 KB
01_09_30 AC 1 ms 256 KB
01_10_23 AC 1 ms 256 KB
01_11_33 AC 1 ms 256 KB
01_12_11 AC 1 ms 256 KB
01_13_28 AC 1 ms 256 KB
01_14_41 AC 1 ms 256 KB
01_15_26 AC 1 ms 256 KB
01_16_49 AC 1 ms 256 KB
01_17_34 AC 1 ms 256 KB
01_18_02 AC 1 ms 256 KB
01_19_33 AC 1 ms 256 KB
01_20_29 AC 1 ms 256 KB
02_00_51254 AC 230 ms 10228 KB
02_01_82431 AC 384 ms 19436 KB
02_02_17056 AC 81 ms 4988 KB
02_03_34866 AC 169 ms 9716 KB
02_04_6779 AC 30 ms 1536 KB
02_05_65534 AC 276 ms 10740 KB
02_06_65535 AC 283 ms 10740 KB
02_07_65536 AC 322 ms 18668 KB
02_08_65537 AC 336 ms 18668 KB
02_09_65538 AC 324 ms 18668 KB
02_10_100000 AC 434 ms 19948 KB