結果

問題 No.320 眠れない夜に
ユーザー Kmcode1Kmcode1
提出日時 2015-12-13 00:25:56
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,420 bytes
コンパイル時間 791 ms
コンパイル使用メモリ 101,060 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-13 12:02:50
合計ジャッジ時間 2,164 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;

long long int m;
int n;

long long int a;
long long int b;
vector<long long int> v;

map<long long int, int> dp[82];
long long int sum[82];
inline long long int dfs(int b, long long int val){
	if (b < 0){
		if (val == 0LL){
			return 0;
		}
		return -1;
	}
	if (val > sum[b]){
		return -1;
	}
	int ans1 = -1;
	int ans2 = -1;
	if (val >= v[b]){
		ans1=dfs(b - 1, val - v[b]);
	}
	if (ans1 != -1){
		ans1++;
	}
	ans2 = dfs(b - 1, val);
	if (ans2 >= 0){
		if (ans1 == -1 || ans1 > ans2){
			ans1 = ans2 ;
		}
	}
	return ans1;
}
int main(){
	scanf("%d", &n);
	scanf("%lld", &m);

	a = 1;
	b = 1;
	v.push_back(1);
	v.push_back(1);
	sum[0] = 1;
	sum[1] = 1;
	for (int i = 2; i < n; i++){
		swap(a, b);
		b += a;
		v.push_back(b);
		sum[v.size() - 1] = sum[v.size() - 2] + b;
	}
	//v.pop_back();
	v.pop_back();
	long long int need = b - m;

	int ans = dfs(v.size()-1, need);
	printf("%d\n", ans);
	return 0;
}
0