結果

問題 No.914 Omiyage
ユーザー jupirojupiro
提出日時 2020-01-16 13:33:33
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,660 bytes
コンパイル時間 1,202 ms
コンパイル使用メモリ 122,896 KB
実行使用メモリ 5,716 KB
最終ジャッジ日時 2024-06-23 16:29:56
合計ジャッジ時間 2,239 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ll N, M, K;
vector<vector<ll>> A;
void dfs(ll cur, ll end, ll res, vector<ll> &v) {
	if (cur == end) {
		v.push_back(res);
		return;
	}
	for (ll i = 0; i < M; i++) {
		dfs(cur + 1, end, res + A[cur][i], v);
	}
}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	scanf("%lld %lld %lld", &N, &M, &K);
	A = vector<vector<ll>>(N, vector<ll>(M)); for (ll i = 0; i < N; i++) for (ll j = 0; j < M; j++) scanf("%lld", &A[i][j]);
	vector<ll> v1, v2;
	dfs(0, N / 2, 0, v1);
	dfs(N / 2, N, 0, v2);
	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	ll res = 0;
	for (ll i = 0; i < v1.size(); i++) {
		auto itr = upper_bound(v2.begin(), v2.end(), K - v1[i]);
		if (itr == v2.begin()) continue;
		chmax(res, *(--itr) + v1[i]);
	}
	if (res == 0) puts("-1");
	else cout << K - res << endl;
	return 0;
}
0