結果

問題 No.2550 MORE! JUMP! MORE!
ユーザー InTheBloomInTheBloom
提出日時 2023-11-20 19:15:49
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 273 ms / 2,000 ms
コード長 1,458 bytes
コンパイル時間 1,988 ms
コンパイル使用メモリ 195,948 KB
実行使用メモリ 11,708 KB
最終ジャッジ日時 2023-11-20 19:16:01
合計ジャッジ時間 9,587 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 1 ms
6,676 KB
testcase_09 AC 1 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 1 ms
6,676 KB
testcase_14 AC 1 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 1 ms
6,676 KB
testcase_17 AC 1 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 171 ms
7,096 KB
testcase_21 AC 91 ms
6,676 KB
testcase_22 AC 29 ms
6,676 KB
testcase_23 AC 149 ms
6,676 KB
testcase_24 AC 261 ms
11,708 KB
testcase_25 AC 156 ms
6,712 KB
testcase_26 AC 114 ms
6,676 KB
testcase_27 AC 218 ms
11,708 KB
testcase_28 AC 184 ms
7,096 KB
testcase_29 AC 128 ms
6,676 KB
testcase_30 AC 268 ms
11,708 KB
testcase_31 AC 273 ms
11,708 KB
testcase_32 AC 269 ms
11,708 KB
testcase_33 AC 269 ms
11,708 KB
testcase_34 AC 269 ms
11,708 KB
testcase_35 AC 270 ms
11,708 KB
testcase_36 AC 272 ms
11,708 KB
testcase_37 AC 269 ms
11,708 KB
testcase_38 AC 272 ms
11,708 KB
testcase_39 AC 269 ms
11,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main () {
    int N = readln.chomp.to!int;
    int[] A = readln.split.to!(int[]);

    solve(N, A);
}

void solve (int N, int[] A) {
    const int MOD = 998244353;

    long ans = 0;
    foreach (i, a; A) {
        long x = cast(int) i + 1;
        long term1 = modPow(2, x-1, MOD);
        long term2 = 0;
        if (2 <= x) term2 = (x-1) * modPow(2, x-2, MOD) % MOD;
        long sum = (term1+term2) % MOD;
        if (x < N) {
            sum *= modPow(2, N-x-1, MOD);
            sum %= MOD;
            ans += a*sum % MOD;
        }
        else {
            ans += a*sum % MOD;
        }

        // dbg
        //writeln("x: ", x, " val: ", a*(term1+term2));
        ans %= MOD;
    }

    writeln(ans);
}

void read(T...)(string S, ref T args) {
    auto buf = S.split;
    foreach (i, ref arg; args) {
        arg = buf[i].to!(typeof(arg));
    }
}

long modPow (long a, long x, const int MOD) {
    // assertion
    assert(0 <= x, format("x = %d", x));
    assert(1 <= MOD);

    // normalize
    a %= MOD; a += MOD; a %= MOD;

    // simple case
    if (MOD == 1) {
        return 0L;
    }

    if (x == 0) {
        return 1L;
    }

    if (x == 1) {
        return a;
    }

    // calculate
    long res = 1L;
    long base = a % MOD;
    while (x != 0) {
        if ((x&1) != 0) {
            res *= base;
            res %= MOD;
        }
        base = base*base; base %= MOD;
        x >>= 1;
    }

    return res;
}
0