Submission #420213
Source Code Expand
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
unsigned inverse(ll a, const unsigned MOD) {
ll b = MOD, u = 1, v = 0;
while(b) {
ll t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
return (u % MOD + MOD) % MOD;
}
typedef unsigned int Num;
namespace FMT {
const Num MOD = 2130706433U;
const int OmegaMax = 23;
Num OmegaPrim = 183; //OmegaPrim^(2^OmegaN) ≡ 1 (mod MOD)
Num Omega[OmegaMax+1];
const int MaxNM = 1<<11; //2D用
inline Num ADD(Num x, Num y) {
if((x += y) >= MOD) x -= MOD;
return x;
}
inline Num MUL(Num x, Num y) {
return (unsigned long long)x * y % MOD;
}
void init() {
Num x = OmegaPrim;
for(int i = OmegaMax; i >= 0; i --) {
Omega[i] = x;
x = MUL(x, x);
}
}
//aを破壊する
void fft_main(int logn, const bool inv, Num a[]) {
int n = 1 << logn;
Num ww = Omega[logn];
if(inv) ww = inverse(ww, MOD);
for(int m = n, mi = 0; m >= 2; m >>= 1, mi ++) {
int mh = m >> 1;
Num w = 1;
rep(i, mh) {
for(int j = i; j < n; j += m) {
int k = j + mh;
Num x = (a[j] < a[k] ? MOD - a[k] + a[j] : a[j] - a[k]);
a[j] = ADD(a[j], a[k]);
a[k] = MUL(w, x);
}
w = MUL(w, ww);
}
ww = MUL(ww, ww);
}
int i = 0;
reu(j, 1, n-1) {
for(int k = n >> 1; k > (i ^= k); k >>= 1) ;
if(j < i) swap(a[i], a[j]);
}
}
void fft(int logn, Num a[]) { fft_main(logn, false, a); }
void inverse_fft(int logn, Num a[]) {
fft_main(logn, true, a);
int n = 1 << logn;
Num invn = inverse(n, MOD);
rep(i, n) a[i] = MUL(a[i], invn);
}
//v, wを破壊し、vに結果を返す
//v, wのサイズは 2^logn, lognはceil(log_2(size(v) + size(w)))必要
void convolution(Num v[], Num w[], int logn) {
fft(logn, v); fft(logn, w);
rep(i, 1<<logn) v[i] = MUL(v[i], w[i]);
inverse_fft(logn, v);
}
}
int main() {
FMT::init();
int N;
while(~scanf("%d", &N)) {
int l = 1;
while((1 << l) < N + 1 + N + 1) ++ l;
vector<Num> v(1 << l), w(1 << l);
rep(i, N) {
int A, B;
scanf("%d%d", &A, &B);
v[i + 1] = A, w[i + 1] = B;
}
FMT::convolution(&v[0], &w[0], l);
rer(i, 1, N + N)
printf("%d\n", (int)v[i]);
}
return 0;
}
Submission Info
Submission Time
2015-06-06 21:06:03+0900
Task
C - 高速フーリエ変換
User
anta
Language
C++ (GCC 4.9.2)
Score
100
Code Size
3347 Byte
Status
AC
Exec Time
328 ms
Memory
2856 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:123:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &A, &B);
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
100 / 100
Status
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
26 ms
796 KB
01_00_01
AC
27 ms
916 KB
01_01_19
AC
22 ms
792 KB
01_02_31
AC
24 ms
920 KB
01_03_22
AC
24 ms
928 KB
01_04_31
AC
24 ms
800 KB
01_05_40
AC
26 ms
804 KB
01_06_15
AC
24 ms
920 KB
01_07_39
AC
24 ms
924 KB
01_08_28
AC
24 ms
840 KB
01_09_30
AC
25 ms
924 KB
01_10_23
AC
25 ms
808 KB
01_11_33
AC
24 ms
932 KB
01_12_11
AC
24 ms
804 KB
01_13_28
AC
24 ms
932 KB
01_14_41
AC
22 ms
812 KB
01_15_26
AC
24 ms
924 KB
01_16_49
AC
24 ms
920 KB
01_17_34
AC
23 ms
800 KB
01_18_02
AC
24 ms
840 KB
01_19_33
AC
25 ms
796 KB
01_20_29
AC
25 ms
920 KB
02_00_51254
AC
171 ms
1816 KB
02_01_82431
AC
308 ms
2852 KB
02_02_17056
AC
75 ms
1316 KB
02_03_34866
AC
149 ms
1832 KB
02_04_6779
AC
37 ms
928 KB
02_05_65534
AC
194 ms
1944 KB
02_06_65535
AC
194 ms
1836 KB
02_07_65536
AC
279 ms
2852 KB
02_08_65537
AC
281 ms
2856 KB
02_09_65538
AC
283 ms
2852 KB
02_10_100000
AC
328 ms
2840 KB