結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー tentententen
提出日時 2021-08-03 10:47:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 221 ms / 2,000 ms
コード長 2,177 bytes
コンパイル時間 4,003 ms
コンパイル使用メモリ 74,248 KB
実行使用メモリ 53,244 KB
最終ジャッジ日時 2023-10-14 21:07:23
合計ジャッジ時間 7,043 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,400 KB
testcase_01 AC 44 ms
49,532 KB
testcase_02 AC 44 ms
49,352 KB
testcase_03 AC 45 ms
49,656 KB
testcase_04 AC 128 ms
50,628 KB
testcase_05 AC 71 ms
50,588 KB
testcase_06 AC 77 ms
50,404 KB
testcase_07 AC 160 ms
53,244 KB
testcase_08 AC 132 ms
48,576 KB
testcase_09 AC 148 ms
51,184 KB
testcase_10 AC 133 ms
50,844 KB
testcase_11 AC 105 ms
50,584 KB
testcase_12 AC 135 ms
50,848 KB
testcase_13 AC 148 ms
51,064 KB
testcase_14 AC 116 ms
50,592 KB
testcase_15 AC 153 ms
53,012 KB
testcase_16 AC 149 ms
51,192 KB
testcase_17 AC 221 ms
53,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int[] counts = new int[10];
        for (int i = 1; i < 10; i++) {
            counts[i] = sc.nextInt();
        }
        long[] factorials = new long[n + 1];
        long[] reverses = new long[n + 1];
        factorials[0] = 1;
        reverses[0] = 1;
        long base = 0;
        for (int i = 1; i <= n; i++) {
            factorials[i] = factorials[i - 1] * i % MOD;
            reverses[i] = powmod(factorials[i], MOD - 2, MOD);
            base *= 10;
            base++;
            base %= MOD;
        }
        base *= factorials[n - 1];
        base %= MOD;
        long ans = 0;
        for (int i = 1; i < 10; i++) {
            if (counts[i] == 0) {
                continue;
            }
            long tmp = base * i % MOD;
            for (int j = 1; j < 10; j++) {
                if (i == j) {
                    tmp *= reverses[counts[j] - 1];
                } else {
                    tmp *= reverses[counts[j]];
                }
                tmp %= MOD;
            }
            ans += tmp;
            ans %= MOD;
        }
        System.out.println(ans);
    }
    
    static long powmod(long x, long p, int m) {
        if (p == 0) {
            return 1;
        } else if (p % 2 == 0) {
            return powmod(x * x % m, p / 2, m);
        } else {
            return powmod(x, p - 1, m) * x % m;
        }
    }
}
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