結果
問題 |
No.294 SuperFizzBuzz
|
ユーザー |
![]() |
提出日時 | 2020-12-23 16:13:36 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 604 ms / 5,000 ms |
コード長 | 1,743 bytes |
コンパイル時間 | 2,984 ms |
コンパイル使用メモリ | 82,860 KB |
実行使用メモリ | 54,404 KB |
最終ジャッジ日時 | 2024-09-21 16:25:19 |
合計ジャッジ時間 | 7,886 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
import java.util.*; public class Main { static final int MAX = 26; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[][] comb = new int[MAX][MAX]; int max = 0; for (int i = 0; i < MAX; i++) { for (int j = 0; j <= i; j++) { if (j == 0 || i == j) { comb[i][j] = 1; } else { comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j]; } } } int[] counts = new int[MAX]; for (int i = 2; i < MAX; i++) { for (int j = 2; j <= i; j += 3) { counts[i] += comb[i][j]; } } int idx = 0; for (int i = 2; i < MAX; i++) { if (n > counts[i]) { n -= counts[i]; } else { idx = i; break; } } for (int i = 0; i < (1 << idx); i++) { if (getCount(i) % 3 == 2) { n--; } if (n == 0) { System.out.println(getNum(i, idx)); return; } } } static String getNum(int x, int length) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < length; i++) { if (x % 2 == 0) { sb.append("3"); } else { sb.append("5"); } x /= 2; } return sb.reverse() + "5"; } static int getCount(int x) { int count = 0; while (x > 0) { count += x % 2; x /= 2; } return count; } }