結果

問題 No.933 おまわりさんこいつです
ユーザー noisy_noiminnoisy_noimin
提出日時 2019-11-29 23:27:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,953 bytes
コンパイル時間 1,144 ms
コンパイル使用メモリ 103,420 KB
実行使用メモリ 68,892 KB
最終ジャッジ日時 2023-08-13 06:54:22
合計ジャッジ時間 7,077 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <numeric>
#include <bitset>
#include <functional>
#include <complex>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

const double PI = acos(-1.0);
const double EPS = 1e-10;

vector< complex<double> > dft(int n, vector< complex<double> > f, bool inv) {
    if(n == 1) {
        return f;
    }
    while(f.size() < n) f.push_back( complex<double>(0.0, 0.0) );

    vector< complex<double> > ff[2];
    for(int i=0;i<n;++i) {
        ff[i%2].push_back(f[i]);
    }
    ff[0] = dft(n/2, ff[0], inv);
    ff[1] = dft(n/2, ff[1], inv);
    double theta = (inv ? 1.0 : -1.0) * 2.0 * PI / n;
    complex<double> zeta(cos(theta), sin(theta));
    complex<double> pow_zeta(1.0, 0.0);
    for(int i=0;i<n;++i) {
        f[i] = ff[0][i % (n/2)] + pow_zeta * ff[1][i % (n/2)];
        pow_zeta *= zeta;
    }
    return f;
}

vector< complex<double> > convolution(vector< complex<double> > g, vector< complex<double> > h) {
    int n_pow2 = 1;
    while(n_pow2 <= int(g.size()+h.size())) n_pow2 <<= 1;

    vector< complex<double> > inv_g = dft(n_pow2, g, false);
    vector< complex<double> > inv_h = dft(n_pow2, h, false);
    vector< complex<double> > inv_f(n_pow2, complex<double>(0.0, 0.0));
    for(int i=0;i<n_pow2;++i) {
        inv_f[i] = inv_g[i] * inv_h[i];
    }
    return dft(n_pow2, inv_f, true);
}

vector<complex<double>> to_vec(ll n) {
    vector<complex<double>> v;
    while(n) {
        v.push_back(complex<double>(n % 10, 0));
        n /= 10;
    }
    return v;
}

ll calc_digit_sum(ll n) {
    ll ret = 0LL;
    while(n) {
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    ll p;
    vector<complex<double>> mul = to_vec(1);
    for(int i=0;i<n;++i) {
        cin >> p;
        vector<complex<double>> v = to_vec(p);
        while(v.size() < mul.size()) v.push_back(complex<double>(0, 0));
        mul = convolution(mul, v);
    }

    int carry = 0;
    for(int j=0;j<mul.size();++j) {
        mul[j].real(mul[j].real() / mul.size());
        if(mul[j].real() < EPS) mul[j].real(0.0);
        mul[j].real(mul[j].real() + double(carry));
        carry = int(mul[j].real()+EPS) / 10;
        mul[j].real(int(mul[j].real()+EPS) % 10);
        mul[j].imag(0.0);
    }
    while(carry) {
        mul.push_back(complex<double>(carry%10, 0));
        carry /= 10;
    }

    ll digit_sum = 0LL;
    for(int i=0;i<mul.size();++i) {
        digit_sum += mul[i].real();
    }
    while(digit_sum >= 10) {
        digit_sum = calc_digit_sum(digit_sum);
    }

    cout << digit_sum << endl;
}
0