結果

問題 No.914 Omiyage
ユーザー rhincodon66
提出日時 2019-10-25 21:55:09
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,354 bytes
コンパイル時間 1,703 ms
コンパイル使用メモリ 177,708 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-24 16:27:45
合計ジャッジ時間 2,501 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
if(y<h && y>=0 && x<w && x>=0) return true;
return false;
}
vector<vector<int>> a(10,vector<int>(10));
int n,m,k;
void dfs(vector<int>&b, int t, int sum, int o){
if(t == o){
b.pb(sum);
return;
}
rep(i,m){
dfs(b,t + 1, sum + a[t][i],o);
}
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m >> k;
rep(i,n){
rep(j,m){
cin >> a[i][j];
}
}
int o = min(n,5);
vector<int> b;
vector<int> c;
dfs(b,0,0,o);
int ans = 100000;
if(n <= 5){
rep(i,b.size()){
if(b.at(i) <= k) ans = min(ans, k - b.at(i));
}
if(ans == 100000) cout << -1 << endl;
else cout << ans << endl;
return 0;
}
dfs(c,o,0,n);
sort(b.begin(),b.end());
sort(c.begin(),c.end());
rep(i,c.size()){
if(c.at(i) > k) break;
int t = lower_bound(b.begin(),b.end(),k - c.at(i)) - b.begin();
if(t == b.size()) t--;
else if(b.at(t) != k - c.at(i)) t--;
if(t >= 0) ans = min(ans, k - b.at(t) - c.at(i));
}
if(ans == 100000) cout << -1 << endl;
else cout << ans << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0