結果

問題 No.1620 Substring Sum
ユーザー kakel-san
提出日時 2021-07-22 22:35:09
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 934 bytes
コンパイル時間 4,709 ms
コンパイル使用メモリ 113,304 KB
実行使用メモリ 28,644 KB
最終ジャッジ日時 2024-07-17 18:49:20
合計ジャッジ時間 4,266 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;

class yuki1
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static void Main()
    {
        var s = ReadLine().Select(c => c - '0').ToArray();

        var key = 998244353;
        var res = 0L;
        var mul = Exp(2, s.Length - 1, key);
        var half = Exp(2, key - 2, key);
        for (var i = s.Length - 1; i >= 0; --i)
        {
            res = (res + s[i] * mul % key) % key;
            mul = (mul * 11 % key) * half % key;
        }
        WriteLine(res);
    }
    static long Exp(int n, int k, int keyNum)
    {
        if (k == 0) return 1;
        if (k == 1) return n % keyNum;
        var half = Exp(n, k / 2, keyNum);
        var result = (half * half) % keyNum;
        return ((k % 2) == 0) ? result : ((result * n) % keyNum);
    }
}
0