AtCoder Typical Contest 001

Submission #2583908

Source codeソースコード

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

#define NDEBUG
#ifdef DEBUG
#include "cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))


int pow_2_at_least(int n) {
#if 0
    int y = 1;
    while (y < n) y <<= 1;
    return y;
#endif
    if (n <= 0) return 0;
    --n;
    n |= n >> 1;
    n |= n >> 2;
    n |= n >> 4;
    n |= n >> 8;
    n |= n >> 16;
    return n + 1;
}

typedef complex<double> Cdbl;

void dft(vector<Cdbl>& f, int n, bool inv=false){ // in-place
    if (n == 1) return;
    int h = n/2;
    vector<Cdbl> f0(h), f1(h);
    for (int i=0; i<h; ++i) {
        f0[i] = f[i*2];
        f1[i] = f[i*2+1];
    }
    dft(f0, h, inv);
    dft(f1, h, inv);
    double th = M_PI * 2 / n;
    if (inv) th = -th;
    Cdbl u(cos(th), sin(th)), ui(1, 0);
    for (int i=0; i<n; ++i) {
        f[i] = f0[i%h] + ui*f1[i%h];
        ui *= u;
    }
}
inline void idft(vector<Cdbl>& f, int n){
    dft(f, n, true);
    rep(i,n) f[i] /= n;
}

int main() {
    int N; cin >> N;
    assert(IN(N,1,100000));

    int _n = pow_2_at_least(N*2 + 1);
    vector<Cdbl> g(_n, 0), h(_n, 0);

    rep(i,N){
        int A,B; cin >> A>>B;
        g[1+i] = A;
        h[1+i] = B;
    }

    dft(g, _n);
    dft(h, _n);
    vector<Cdbl> f(_n, 0);
    rep(i,_n) f[i] = g[i] * h[i];
    idft(f, _n);

    rep1(k, N*2){
        cout << (ll)round(f[k].real()) << endl;
    }
    return 0;
}

Submission

Task問題 C - 高速フーリエ変換
User nameユーザ名 naoya_t
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 100
Source lengthソースコード長 2375 Byte
File nameファイル名
Exec time実行時間 866 ms
Memory usageメモリ使用量 20764 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 5 ms 640 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 2 ms 256 KB
01_06_15 AC 1 ms 256 KB
01_07_39 AC 2 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 2 ms 256 KB
01_12_11 AC 1 ms 256 KB
01_13_28 AC 1 ms 256 KB
01_14_41 AC 2 ms 256 KB
01_15_26 AC 1 ms 256 KB
01_16_49 AC 2 ms 256 KB
01_17_34 AC 2 ms 256 KB
01_18_02 AC 1 ms 256 KB
01_19_33 AC 2 ms 256 KB
01_20_29 AC 1 ms 256 KB
02_00_51254 AC 423 ms 10532 KB
02_01_82431 AC 798 ms 20764 KB
02_02_17056 AC 183 ms 5420 KB
02_03_34866 AC 371 ms 10532 KB
02_04_6779 AC 53 ms 1532 KB
02_05_65534 AC 481 ms 10532 KB
02_06_65535 AC 476 ms 10532 KB
02_07_65536 AC 740 ms 20764 KB
02_08_65537 AC 748 ms 20764 KB
02_09_65538 AC 740 ms 20764 KB
02_10_100000 AC 866 ms 20764 KB