結果
| 問題 |
No.933 おまわりさんこいつです
|
| コンテスト | |
| ユーザー |
noisy_noimin
|
| 提出日時 | 2019-11-29 23:27:13 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,953 bytes |
| コンパイル時間 | 1,079 ms |
| コンパイル使用メモリ | 106,224 KB |
| 実行使用メモリ | 344,676 KB |
| 最終ジャッジ日時 | 2024-11-20 23:54:25 |
| 合計ジャッジ時間 | 57,144 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 WA * 4 TLE * 18 |
ソースコード
#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;
}
noisy_noimin