結果

問題 No.2593 Reorder and Mod 120
ユーザー tenten
提出日時 2024-08-01 10:58:43
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,794 bytes
コンパイル時間 2,534 ms
コンパイル使用メモリ 87,340 KB
実行使用メモリ 54,288 KB
最終ジャッジ日時 2024-08-01 10:58:51
合計ジャッジ時間 6,405 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static boolean[] enable = new boolean[120];
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int[] counts = new int[9];
        for (char c : sc.next().toCharArray()) {
            counts[c - '1']++;
        }
        calc(Math.min(n, 3), counts, 0);
        System.out.println(IntStream.range(0, 120).filter(i -> enable[i]).count());
    }
    
    static void calc(int idx, int[] counts, int value) {
        if (idx == 0) {
            enable[value % 120] = true;
            return;
        }
        for (int i = 0; i < 9; i++) {
            if (counts[i] == 0) {
                continue;
            }
            counts[i]--;
            calc(idx - 1, counts, value * 10 + i + 1);
            counts[i]++;
        }
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}


0