結果
問題 | No.1307 Rotate and Accumulate |
ユーザー | t33f |
提出日時 | 2020-12-04 21:58:05 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 241 ms / 5,000 ms |
コード長 | 1,609 bytes |
コンパイル時間 | 920 ms |
コンパイル使用メモリ | 93,224 KB |
実行使用メモリ | 20,876 KB |
最終ジャッジ日時 | 2023-10-13 11:40:26 |
合計ジャッジ時間 | 4,705 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,352 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 2 ms
4,356 KB |
testcase_03 | AC | 1 ms
4,352 KB |
testcase_04 | AC | 2 ms
4,352 KB |
testcase_05 | AC | 1 ms
4,352 KB |
testcase_06 | AC | 2 ms
4,348 KB |
testcase_07 | AC | 2 ms
4,348 KB |
testcase_08 | AC | 186 ms
20,360 KB |
testcase_09 | AC | 187 ms
20,276 KB |
testcase_10 | AC | 127 ms
11,896 KB |
testcase_11 | AC | 100 ms
11,996 KB |
testcase_12 | AC | 125 ms
11,844 KB |
testcase_13 | AC | 28 ms
4,352 KB |
testcase_14 | AC | 58 ms
7,508 KB |
testcase_15 | AC | 227 ms
20,568 KB |
testcase_16 | AC | 234 ms
20,548 KB |
testcase_17 | AC | 230 ms
20,872 KB |
testcase_18 | AC | 210 ms
20,876 KB |
testcase_19 | AC | 237 ms
20,496 KB |
testcase_20 | AC | 241 ms
20,616 KB |
testcase_21 | AC | 1 ms
4,352 KB |
ソースコード
#include <vector> #include <iostream> #include <complex> using namespace std; using C = complex<double>; const double PI = acos(-1); void fft(vector<C> &a, bool inv) { int n = a.size(); if (n == 1) return; vector<C> a0(n / 2), a1(n / 2); for (int i = 0; 2 * i < n; i++) { a0[i] = a[2*i]; a1[i] = a[2*i+1]; } fft(a0, inv); fft(a1, inv); const double ang = 2 * PI / n * (inv ? -1 : 1); const C wn(cos(ang), sin(ang)); C w(1); for (int i = 0; 2 * i < n; i++) { a[i] = a0[i] + w * a1[i]; a[i + n/2] = a0[i] - w * a1[i]; if (inv) { a[i] /= 2; a[i + n/2] /= 2; } w *= wn; } } vector<long long> multiply(vector<int> const& a, vector<int> const& b) { vector<C> fa(a.begin(), a.end()), fb(b.begin(), b.end()); int n = 1; while (n < a.size() + b.size()) n <<= 1; fa.resize(n); fb.resize(n); fft(fa, false); fft(fb, false); for (int i = 0; i < n; i++) fa[i] *= fb[i]; fft(fa, true); vector<long long> result(n); for (int i = 0; i < n; i++) result[i] = round(fa[i].real()); return result; } int main() { int n, q; cin >> n >> q; vector<int> a(n, 0), b(n+1, 0); for (int i = 0; i < n; i++) { cin >> a[i]; } while (q--) { int r; cin >> r; b[n-r]++; } vector<long long> v = multiply(a, b); for (int i = 0; i < n; i++) { long long ans = 0; for (int j = i; j < v.size(); j += n) ans += v[j]; cout << ans << ' '; } cout << endl; }