結果

問題 No.1644 Eight Digits
ユーザー AsahiAsahi
提出日時 2023-02-04 19:57:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 165 ms / 1,000 ms
コード長 2,957 bytes
コンパイル時間 3,812 ms
コンパイル使用メモリ 74,904 KB
実行使用メモリ 56,196 KB
最終ジャッジ日時 2023-09-16 16:29:10
合計ジャッジ時間 10,283 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 161 ms
55,700 KB
testcase_01 AC 146 ms
55,696 KB
testcase_02 AC 148 ms
55,908 KB
testcase_03 AC 161 ms
56,196 KB
testcase_04 AC 162 ms
55,848 KB
testcase_05 AC 162 ms
55,336 KB
testcase_06 AC 161 ms
55,816 KB
testcase_07 AC 145 ms
55,472 KB
testcase_08 AC 146 ms
55,696 KB
testcase_09 AC 161 ms
55,708 KB
testcase_10 AC 165 ms
55,360 KB
testcase_11 AC 162 ms
55,608 KB
testcase_12 AC 162 ms
55,600 KB
testcase_13 AC 162 ms
55,848 KB
testcase_14 AC 161 ms
55,968 KB
testcase_15 AC 163 ms
55,792 KB
testcase_16 AC 161 ms
55,772 KB
testcase_17 AC 162 ms
55,684 KB
testcase_18 AC 160 ms
55,560 KB
testcase_19 AC 147 ms
55,820 KB
testcase_20 AC 162 ms
55,700 KB
testcase_21 AC 162 ms
55,968 KB
testcase_22 AC 161 ms
55,692 KB
testcase_23 AC 148 ms
55,480 KB
testcase_24 AC 147 ms
55,632 KB
testcase_25 AC 146 ms
55,704 KB
testcase_26 AC 145 ms
55,700 KB
testcase_27 AC 146 ms
55,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main{
    /* 入出力 */
    static BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static PrintWriter output = new PrintWriter(System.out);
    static Scanner sc = new Scanner(System.in);
    /* 定数 */
    static final int [] y4 = {0,1,0,-1};
    static final int [] x4 = {1,0,-1,0};
    static final int  INF1 = Integer.MAX_VALUE;
    static final long INF2 = Long.MAX_VALUE;
    static final long MOD1 = (long)1e9+7;
    static final long MOD2 = 998244353;
    static int ans = 0;
    static int k;
    /* Main */
    public static void main(String[] args) throws IOException{
        k = sc.nextInt();
        Perm p = new Perm(8);
        p.next_permutation1(0,8);
        output.print(ans);
        output.flush();
    }
        /* 順列 */
        static class Perm{
            int [] perm ;
            int [] tmp ;
            int [] used;
            String [] perm2;
            String [] tmp2;
            /*コンストラクタ */
            public Perm(int N) {
                this.perm = new int[N];
                this.tmp = new int[N];
                this.used = new int[N];
                this.perm2 = new String[N];
                this.tmp2 = new String[N];
                for(int i=0;i<N;i++) perm[i] = (i+1);
            }
            /*重複無*/
            public void next_permutation1(int pos,int N) {
                if(pos == N) {
                    int num = 0;
                    for(int i=0;i<N;i++) num += tmp[i]*Math.pow(10,N-i-1);
                    if(num % k == 0) ans++;
                    return;
                }
                for(int i=0;i<N;i++) {
                    if(used[i] == 1) continue;
                    used[i] = 1;
                    tmp[pos] = perm[i];
                    next_permutation1(pos+1,N);
                    used[i] = 0;
                }
            }
            /*重複有 */
            public void next_permutation2(int pos,int N,int front) {
                if(pos == N) {
                    /*
                     * 処理
                     */
                    return;
                }
                for(int i=0;i<N;i++) {
                    tmp[pos] = perm[i];
                    next_permutation2(pos+1,N,i);
                }
            }
            /*文字列の順列 */
            public void next_permutationS(int pos,int N) {
                if(pos == N) {
                    /*
                     * 処理
                     */
                    return;
                }
                for(int i=0;i<N;i++) {
                    if(used[i] == 1) continue;
                    used[i] = 1;
                    tmp2[pos] = perm2[i];
                    next_permutationS(pos+1,N);
                    used[i] = 0;
                }
            }
        }
}
0