結果

問題 No.3 ビットすごろく
ユーザー fusen4fusen4
提出日時 2018-01-21 17:28:36
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 898 bytes
コンパイル時間 1,930 ms
コンパイル使用メモリ 59,780 KB
実行使用メモリ 7,672 KB
最終ジャッジ日時 2023-08-26 19:43:48
合計ジャッジ時間 8,401 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;

class Sugo{
				private:
								int N;
								int w[10000];
								bool e[10000];
				public:
								Sugo(int n);
								int fanc(int n);
};

Sugo::Sugo(int _N){
				N = _N;
				for(int i = 0; i < N; i++){
								e[i] = false;
				}

				for(int i = 0; i < N; i++){
								int tw = 1,rest = i + 1;
								while(rest != 1){
												if(rest%2) tw++;
												rest /= 2;
								}
								w[i] = tw;
				}
				e[N - 1] = true;
}
int Sugo::fanc(int n){
				int c = 0;
				if(n == 1) return 1;
				for(int i = 0; i < N; i++){
								if(( i + 1 + w[i] == n || i + 1 - w[i] == n )&& !e[i]){
												e[i] = true;
												c += fanc(i + 1) + 1; 
												e[i] = false;
								}
				}
				if(c == 0) return -1;
				else return c;
}


int main(){
				int n;
				cin >> n;
				Sugo t(n);
				cout << t.fanc(n) << endl;
}

0