結果
問題 | No.914 Omiyage |
ユーザー |
![]() |
提出日時 | 2020-04-19 18:21:11 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 15 ms / 2,000 ms |
コード長 | 1,092 bytes |
コンパイル時間 | 2,690 ms |
コンパイル使用メモリ | 208,224 KB |
最終ジャッジ日時 | 2025-01-09 21:41:17 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; int main() { int N, M, K; cin >> N >> M >> K; int X = (N + 1) / 2, Y = N / 2; assert(X + Y == N); vector<vector<int>> A(X, vector<int>(M)); vector<vector<int>> B(Y, vector<int>(M)); for(int i = 0; i < X; ++i) { for(int j = 0; j < M; ++j) cin >> A[i][j]; } for(int i = 0; i < Y; ++i) { for(int j = 0; j < M; ++j) cin >> B[i][j]; } map<int, int> ma, ma2; auto rec = [&](auto &&rec, int now, int d) -> void { if(d == X) { ma[now]++; return; } for(int i = 0; i < M; ++i) rec(rec, now + A[d][i], d + 1); }; rec(rec, 0, 0); auto rec2 = [&](auto &&rec2, int now, int d) -> void { if(d == Y) { ma2[now]++; return; } for(int i = 0; i < M; ++i) rec2(rec2, now + B[d][i], d + 1); }; rec2(rec2, 0, 0); int ans = INF; for(auto &[v, key] : ma) { for(int a = 0; a < K; ++a) { if(ma2[K - a - v]) ans = min(ans, a); } } if(ans == INF) ans = -1; cout << ans << '\n'; return 0; }