結果
| 問題 |
No.294 SuperFizzBuzz
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-11-11 12:51:16 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,556 bytes |
| コンパイル時間 | 2,517 ms |
| コンパイル使用メモリ | 83,016 KB |
| 実行使用メモリ | 51,492 KB |
| 最終ジャッジ日時 | 2024-11-22 17:15:49 |
| 合計ジャッジ時間 | 6,943 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 WA * 3 |
ソースコード
import java.util.*;
import java.io.*;
public class Main {
static long[][] comb = new long[200][200];
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
long n = sc.nextInt() - 1;
for (int i = 0; i < 200; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0 || j == i) {
comb[i][j] = 1;
} else {
comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
}
}
}
int count = 2;
while (true) {
long sum = getSum(count);
if (n <= sum) {
break;
}
n -= sum;
count++;
}
System.out.println(getString(count, n + 1) + "5");
}
static long getSum(int count) {
long sum = 0;
for (int i = 0; i * 3 + 2 <= count; i++) {
sum += getSum(count, i * 3 + 2);
}
return sum;
}
static long getSum(int all, int part) {
return comb[all][part];
}
static String getString(int count, long size) {
int mask = 0;
for (int i = 0; i < size; i++) {
mask++;
while (getPop(mask) % 3 < 2) {
mask++;
}
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < count; i++) {
if (mask % 2 == 0) {
sb.append("3");
} else {
sb.append("5");
}
mask >>= 1;
}
return sb.reverse().toString();
}
static int getPop(int x) {
int pop = 0;
while (x > 0) {
pop += x % 2;
x /= 2;
}
return pop;
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public double nextDouble() throws Exception {
return Double.parseDouble(next());
}
public String nextLine() throws Exception {
return br.readLine();
}
public String next() throws Exception {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten