結果
| 問題 |
No.2593 Reorder and Mod 120
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2024-08-01 11:00:36 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 150 ms / 2,000 ms |
| コード長 | 1,791 bytes |
| コンパイル時間 | 3,262 ms |
| コンパイル使用メモリ | 80,880 KB |
| 実行使用メモリ | 52,460 KB |
| 最終ジャッジ日時 | 2024-08-01 11:00:44 |
| 合計ジャッジ時間 | 7,431 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 26 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
public class Main {
static boolean[] enable = new boolean[40];
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, 40).filter(i -> enable[i]).count());
}
static void calc(int idx, int[] counts, int value) {
if (idx == 0) {
enable[value % 40] = 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();
}
}
}
tenten