結果

問題 No.1644 Eight Digits
ユーザー Asahi
提出日時 2023-02-04 19:57:56
言語 Java
(openjdk 23)
結果
AC  
実行時間 199 ms / 1,000 ms
コード長 2,957 bytes
コンパイル時間 2,516 ms
コンパイル使用メモリ 79,716 KB
実行使用メモリ 54,572 KB
最終ジャッジ日時 2024-07-03 16:29:33
合計ジャッジ時間 9,009 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

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