結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー merlinmerlin
提出日時 2021-07-30 21:16:31
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,477 ms / 2,000 ms
コード長 1,243 bytes
コンパイル時間 3,027 ms
コンパイル使用メモリ 74,012 KB
実行使用メモリ 54,052 KB
最終ジャッジ日時 2023-10-14 02:55:54
合計ジャッジ時間 11,544 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,532 KB
testcase_01 AC 44 ms
49,152 KB
testcase_02 AC 44 ms
49,204 KB
testcase_03 AC 43 ms
49,320 KB
testcase_04 AC 139 ms
52,128 KB
testcase_05 AC 84 ms
52,140 KB
testcase_06 AC 88 ms
52,128 KB
testcase_07 AC 454 ms
54,012 KB
testcase_08 AC 283 ms
52,196 KB
testcase_09 AC 480 ms
52,152 KB
testcase_10 AC 296 ms
53,212 KB
testcase_11 AC 267 ms
51,972 KB
testcase_12 AC 727 ms
51,876 KB
testcase_13 AC 796 ms
52,164 KB
testcase_14 AC 545 ms
52,036 KB
testcase_15 AC 822 ms
54,052 KB
testcase_16 AC 801 ms
51,912 KB
testcase_17 AC 1,477 ms
53,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(bu.readLine());
        int i,a[]=new int[9];
        String s[]=bu.readLine().split(" ");
        for(i=0;i<9;i++) a[i]=Integer.parseInt(s[i]);

        long f[]=new long[n+1],p[]=new long[n+1],M=1000000007;
        f[0]=p[0]=1;
        for(i=1;i<=n;i++)
        {
            f[i]=f[i-1]*i%M;
            p[i]=p[i-1]*10%M;
        }

        long ans=0,v,fa; int j,k;
        for(i=n-1;i>=0;i--)
        {
            v=0;
            for(j=0;j<9;j++)
            if(a[j]!=0)
            {
                fa=1;
                a[j]--;
                for(k=0;k<9;k++)
                fa=fa*f[a[k]]%M;
                fa=f[n-1]*power(fa,M-2,M)%M;
                v=(v+fa*(j+1))%M;
                a[j]++;
            }
            ans=(ans+v*p[i]%M)%M;
        }
        System.out.print(ans);
    }

    static long power(long a,long b,long M)
    {
        long res=1;
        while(b!=0)
        {
            if(b%2==1) res=res*a%M;
            b>>=1;
            a=a*a%M;
        }
        return res;
    }
}
0