結果

問題 No.1618 Convolution?
ユーザー kokatsukokatsu
提出日時 2021-10-25 22:13:32
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 200 ms / 2,000 ms
コード長 870 bytes
コンパイル時間 4,909 ms
コンパイル使用メモリ 205,924 KB
実行使用メモリ 27,716 KB
最終ジャッジ日時 2023-09-04 14:39:52
合計ジャッジ時間 11,312 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 130 ms
17,220 KB
testcase_03 AC 156 ms
21,384 KB
testcase_04 AC 128 ms
17,624 KB
testcase_05 AC 12 ms
4,504 KB
testcase_06 AC 166 ms
19,768 KB
testcase_07 AC 168 ms
20,340 KB
testcase_08 AC 130 ms
17,604 KB
testcase_09 AC 200 ms
27,480 KB
testcase_10 AC 137 ms
16,860 KB
testcase_11 AC 192 ms
27,716 KB
testcase_12 AC 196 ms
23,452 KB
testcase_13 AC 196 ms
22,612 KB
testcase_14 AC 196 ms
22,732 KB
testcase_15 AC 196 ms
23,008 KB
testcase_16 AC 195 ms
22,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main() {
    int N;
    readf("%d\n", N);

    auto A = readln.chomp.split.to!(long[]);
    auto B = readln.chomp.split.to!(long[]);

    auto X = A.cumulativeFold!"a + b".array;
    auto Y = B.cumulativeFold!"a + b".array;

    auto C = new long[](N*2); 

    auto S = new long[](N+1);
    auto T = new long[](N+1);
    foreach (i; 0 .. N) {
        S[i+1] = S[i] + X[i];
        T[i+1] = T[i] + Y[i];
        C[i+1] = S[i+1] + T[i+1];
    }

    auto U = new long[](N);
    auto V = new long[](N);
    U[0] = S[N];
    V[0] = T[N];
    foreach (i; 1 .. N) {
        U[i] = U[i-1] + X[N-1] - X[i-1] - N * A[i-1];
        V[i] = V[i-1] + Y[N-1] - Y[i-1] - N * B[i-1];
        C[N+i] = U[i] + V[i];
    }

    foreach (i, c; C) {
        if (i == N * 2 - 1) {
            writeln(c);
        }
        else {
            write(c, " ");
        }
    }
}
0