結果
問題 | No.294 SuperFizzBuzz |
ユーザー | tenten |
提出日時 | 2020-12-23 16:13:36 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 604 ms / 5,000 ms |
コード長 | 1,743 bytes |
コンパイル時間 | 3,094 ms |
コンパイル使用メモリ | 82,872 KB |
実行使用メモリ | 57,628 KB |
最終ジャッジ日時 | 2023-10-21 15:11:24 |
合計ジャッジ時間 | 8,902 ms |
ジャッジサーバーID (参考情報) |
judge10 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 137 ms
57,028 KB |
testcase_01 | AC | 138 ms
57,364 KB |
testcase_02 | AC | 601 ms
57,500 KB |
testcase_03 | AC | 140 ms
57,508 KB |
testcase_04 | AC | 137 ms
57,512 KB |
testcase_05 | AC | 137 ms
57,300 KB |
testcase_06 | AC | 140 ms
57,532 KB |
testcase_07 | AC | 139 ms
57,088 KB |
testcase_08 | AC | 168 ms
57,412 KB |
testcase_09 | AC | 424 ms
57,364 KB |
testcase_10 | AC | 140 ms
57,392 KB |
testcase_11 | AC | 520 ms
57,628 KB |
testcase_12 | AC | 554 ms
57,560 KB |
testcase_13 | AC | 581 ms
57,404 KB |
testcase_14 | AC | 604 ms
57,604 KB |
ソースコード
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; } }