結果

問題 No.1620 Substring Sum
ユーザー tentententen
提出日時 2021-07-26 20:51:58
言語 Java21
(openjdk 21)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 1,320 bytes
コンパイル時間 2,125 ms
コンパイル使用メモリ 74,540 KB
実行使用メモリ 53,864 KB
最終ジャッジ日時 2023-09-29 17:58:32
合計ジャッジ時間 7,556 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,872 KB
testcase_01 AC 43 ms
49,392 KB
testcase_02 AC 43 ms
49,496 KB
testcase_03 AC 43 ms
49,660 KB
testcase_04 AC 203 ms
53,760 KB
testcase_05 AC 197 ms
53,260 KB
testcase_06 AC 205 ms
53,168 KB
testcase_07 AC 204 ms
53,864 KB
testcase_08 AC 204 ms
53,644 KB
testcase_09 AC 204 ms
53,760 KB
testcase_10 AC 209 ms
53,616 KB
testcase_11 AC 204 ms
53,548 KB
testcase_12 AC 91 ms
51,476 KB
testcase_13 AC 203 ms
53,776 KB
testcase_14 AC 182 ms
52,776 KB
testcase_15 AC 157 ms
53,028 KB
testcase_16 AC 143 ms
52,892 KB
testcase_17 AC 148 ms
52,372 KB
testcase_18 AC 42 ms
49,884 KB
testcase_19 AC 43 ms
49,420 KB
testcase_20 AC 207 ms
53,572 KB
testcase_21 AC 207 ms
53,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    static final int MOD = 998244353;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        char[] arr = sc.next().toCharArray();
        int length = arr.length;
        long ans = 0;
        for (int i = 0; i < length; i++) {
            ans += pow(11, length - i - 1) * (arr[i] - '0') % MOD * pow(2, i) % MOD;
            ans %= MOD;
        }
        System.out.println(ans);
    }
    
    static long pow(long x, int p) {
        if (p == 0) {
            return 1;
        } else if (p % 2 == 0) {
            return pow(x * x % MOD, p / 2);
        } else {
            return pow(x, p - 1) * x % MOD;
        }
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0