結果
| 問題 | No.320 眠れない夜に |
| コンテスト | |
| ユーザー |
Bantako
|
| 提出日時 | 2018-07-09 12:21:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,393 bytes |
| 記録 | |
| コンパイル時間 | 1,609 ms |
| コンパイル使用メモリ | 181,000 KB |
| 実行使用メモリ | 117,888 KB |
| 最終ジャッジ日時 | 2024-07-08 00:51:46 |
| 合計ジャッジ時間 | 8,398 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | TLE * 1 -- * 30 |
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
7 | main(){
| ^~~~
ソースコード
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
ll N,M;
cin >> N >> M;
vector<ll> V(N);
V[0] = V[1] = 1;
rep(i,2,N)V[i] = V[i-1] + V[i-2];
ll dif = V[N-1] - M;
cout << dif << endl;
//V[N-2]までの和でdifを表せるかどうか
map<ll,int> mp;
mp[0] = 0;
rep(i,0,N-1){
map<ll,int> mp2;
for(auto p:mp){
rep(k,0,2){
ll next = V[i] + p.first;
if(k)next = p.first;
if(next > M)continue;
vector<int> vec;
vec.push_back(p.second + 1);
if(mp2.find(next) != mp2.end() )vec.push_back(mp2[next]);
if(mp.find(next) != mp.end() )vec.push_back(mp[next]);
int mini = INF;
for(auto i:vec)mini = min(mini, i);
mp2[next] = mini;
}
}
//mp = mp2;
mp.clear();
for(auto p:mp2){
mp[p.first] = p.second;
// cout << p.first << " " << p.second << endl;
}
//cout << "-----" << endl;
}
for(auto p:mp){
//cout << p.first << " " << p.second << endl;
}
if(mp.find(dif) != mp.end())cout << mp[dif] << endl;
else cout << -1 << endl;
}
Bantako