結果

問題 No.320 眠れない夜に
ユーザー Kmcode1Kmcode1
提出日時 2015-12-13 00:30:54
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,410 bytes
コンパイル時間 1,409 ms
コンパイル使用メモリ 103,196 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-15 10:41:36
合計ジャッジ時間 2,286 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:67:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   67 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
main.cpp:68:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   68 |         scanf("%lld", &m);
      |         ~~~~~^~~~~~~~~~~~

ソースコード

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;

__int128 a;
__int128 b;
vector<__int128> v;

map<__int128, int> dp[82];
__int128 sum[82];
inline long long int dfs(int b, __int128 val){
	if (b < 0){
		if (val == 0LL){
			return 0;
		}
		return -1;
	}
	if (sum[b] < val){
		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] = 2;
	for (int i = 2; i < n; i++){
		swap(a, b);
		b += a;
		v.push_back(b);
		sum[v.size() - 1] = (__int128)(sum[v.size() - 2]) + (__int128)(b);
	}
	v.pop_back();
	v.pop_back();
	__int128 need = b - m;

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