結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー tentententen
提出日時 2023-04-17 17:34:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 2,550 bytes
コンパイル時間 2,888 ms
コンパイル使用メモリ 84,980 KB
実行使用メモリ 37,932 KB
最終ジャッジ日時 2024-04-20 21:03:54
合計ジャッジ時間 4,741 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
36,984 KB
testcase_01 AC 55 ms
37,064 KB
testcase_02 AC 56 ms
37,228 KB
testcase_03 AC 54 ms
36,976 KB
testcase_04 AC 65 ms
37,384 KB
testcase_05 AC 56 ms
37,132 KB
testcase_06 AC 56 ms
37,252 KB
testcase_07 AC 72 ms
37,288 KB
testcase_08 AC 67 ms
37,464 KB
testcase_09 AC 70 ms
37,580 KB
testcase_10 AC 65 ms
37,236 KB
testcase_11 AC 62 ms
37,232 KB
testcase_12 AC 65 ms
37,492 KB
testcase_13 AC 68 ms
37,596 KB
testcase_14 AC 61 ms
37,312 KB
testcase_15 AC 69 ms
37,580 KB
testcase_16 AC 68 ms
36,984 KB
testcase_17 AC 73 ms
37,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        long[] counts = new long[10];
        long facts = 1;
        for (int i = 1; i <= 9; i++) {
            counts[i] = sc.nextInt();
            for (int j = 2; j <= counts[i]; j++) {
                facts *= j;
                facts %= MOD;
            }
        }
        facts = pow(facts, MOD - 2);
        long base = 0;
        long all = 1;
        for (int i = 1; i <= n; i++) {
            base *= 10;
            base++;
            base %= MOD;
            if (i < n) {
                all *= i;
                all %= MOD;
            }
        }
        long ans = 0;
        for (int i = 1; i <= 9; i++) {
            if (counts[i] > 0) {
                ans += all * base % MOD * i % MOD * facts % MOD * counts[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 Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0