結果

問題 No.914 Omiyage
ユーザー 👑 jupirojupiro
提出日時 2020-01-16 13:33:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,660 bytes
コンパイル時間 1,224 ms
コンパイル使用メモリ 122,556 KB
実行使用メモリ 5,640 KB
最終ジャッジ日時 2023-09-05 21:07:12
合計ジャッジ時間 2,859 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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