結果
| 問題 |
No.914 Omiyage
|
| コンテスト | |
| ユーザー |
ate
|
| 提出日時 | 2019-10-25 22:56:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,532 bytes |
| コンパイル時間 | 1,978 ms |
| コンパイル使用メモリ | 204,096 KB |
| 最終ジャッジ日時 | 2025-01-08 01:34:59 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 TLE * 6 |
コンパイルメッセージ
main.cpp:30:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
30 | main(){
| ^~~~
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
ll ans;
int n,m,k;
void dfs(ll t,int i,vector<vector<ll>>& a){
if(k-t<0)return;
if(i+1==n){
chmin(ans,k-t);
return;
}
for(int nx=m-1;nx>=0;--nx){
dfs(t+a[i+1][nx],i+1,a);
}
}
main(){
cin>>n>>m>>k;
auto a = make_vector<ll>(n,m);
cin>>a;
ans=INF;
dfs(a[0][0],0,a);
if(ans==INF){cout<<(-1)<<endl;return 0;}
using pll = pair<ll,ll>;
// value,i_index
priority_queue<pll> que;
rep(j,m){
que.emplace(a[0][j],0);
}
while(!que.empty()){
auto [val,idx]=que.top();que.pop();
idx++;
if(k-val<0)continue;
if(idx==n){chmin(ans,k-val);continue;}
for(int j=0;j<m;++j){
que.emplace(val+a[idx][j],idx);
}
}
cout<<(ans)<<endl;
}
ate