結果

問題 No.914 Omiyage
ユーザー soto800soto800
提出日時 2019-10-25 22:15:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 826 bytes
コンパイル時間 2,544 ms
コンパイル使用メモリ 167,632 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 21:16:22
合計ジャッジ時間 2,240 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())

signed main(){
 
	lli n,m,k;
	cin>>n>>m>>k;

	lli data[12][12];

	REP(i,0,n)REP(j,0,m)cin>>data[i][j];

	unordered_set<lli> s;

	REP(i,0,m)s.insert(data[0][i]);

	REP(i,1,n){
		unordered_set<lli> next;
		for(auto e:s){
			REP(j,0,m){
				if(data[i][j]<=k){
					if(DEBUG)cout<<"nextPush ="<<e+data[i][j]<<endl;
					next.insert(e+data[i][j]);
				}
			}
		}
		s.clear();
		for(auto e:next){
			s.insert(e);
		}
	}

	lli ans = INF;
	for(auto e:s){
		if(k-e<0)continue;
		ans = min(ans,k-e);
	}
	if(ans == INF)cout<<-1<<endl;
	else cout<<ans<<endl;

	return 0;
}
0