結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-03-20 15:28:29 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,123 bytes |
| コンパイル時間 | 3,591 ms |
| コンパイル使用メモリ | 79,728 KB |
| 実行使用メモリ | 56,880 KB |
| 最終ジャッジ日時 | 2024-07-05 03:20:09 |
| 合計ジャッジ時間 | 11,270 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 WA * 32 |
ソースコード
import java.util.ArrayList;
import java.util.Scanner;
public class Bitsugoroku {
static int N;
static boolean tof = false;
static ArrayList<Integer> list = new ArrayList<>();
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int p = 1,count = 1;
N = s.nextInt();
s.close();
if(N == 1){
count = 1;
}else{
int h = Sugo(p,count);
if(h == 0){
count = 0;
}else{
count += h;
}
}
if(count == 0){
System.out.println(-1);
}else{
System.out.println(count);
}
}
static int Sugo(int p,int count){
int d = Integer.bitCount(p);
if(list.contains(p)){
return 0;
}
list.add(p);
if(p + d > N){
System.out.println(">\t"+d);
tof = true;
int k = Sugo(p - d,count);
if(k == 0){
count = 0;
}else{
count += k;
}
}else if(p + d == N){
System.out.println("==\t"+d);
count = 1;
}else{
System.out.println("else\t"+d);
int ph = Sugo(p+d,count);
if(ph>0){
count += ph;
}else{
int nh = Sugo(p+d,count);
if(nh > 0){
count += nh;
}else{
count = 0;
}
}
}
return count;
}
}